Issue
I trying to populate a Spinner with a List of Strings. He compiles and run in android, but when I enter a touch in the Spinner, the program stops and return this error:
android.content.res.Resources$NotFoundException: Resource ID #0x7f090003 type #0x12 is not valid
protected void onPostExecute(List<String> myList)
{
if (!myList.isEmpty())
{
ArrayAdapter<String> adp = new ArrayAdapter<String>(MyActivity.this, android.R.layout.simple_spinner_item, myList);
adp.setDropDownViewResource(R.id.mySpinner);
mySpinner.setAdapter(adp);
}
else
{
Toast.makeText(getApplicationContext(), "Warning.", Toast.LENGTH_SHORT).show();
Intent i = new Intent(myActivity.this, Preferences.class);
startActivity(i);
}
}
Solution
I think setDropDownViewResource
method expects a layout resource ID.
You should replace
adp.setDropDownViewResource(R.id.mySpinner);
by
adp.setDropDownViewResource(R.layout.mySpinner);
And make sure (of course) that the file res/layout/mySpinner.xml
exists
Or just use a default layout from the SDK:
adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Answered By - sdabet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.