Skip to content Skip to sidebar Skip to footer

Android Spinner Give A Nullpointexception

Any ideas why this code throws a NullPointException? Spinner spinnerLoadLayouts = (Spinner)this.findViewById(R.id.spnLoadLay); ArrayAdapter adapter =

Solution 1:

I guess that the View or Activity cannot find R.id.spnLoadLay

Quote:

findViewById: Returns: The View that has the given tag in the hierarchy or null

Solution 2:

If the error is on the last line, then spinnerLoadLayouts is NULL.

This could be because you can only do this

(Spinner)this.findViewById(R.id.spnLoadLay);

If the spnLoadLay view is actually in the current view (is available in an XML you have allready called setContentView on for instance). If you haven't put that on the screen, you can't find it using findViewById. You need to use an Inflater for that

Post a Comment for "Android Spinner Give A Nullpointexception"