Petar Mijović Petar Mijović - 9 months ago 72
Android Question

Xamarin Resource ID #0x7f050000 type #0x12 is not valid

I read few similar threads here, but none of the solutions works. I am pretty new in Xamarin Programming.

This is the code that creates the problem:

try
{
var combo = FindViewById<Spinner>(Resource.Id.spinner);
ArrayAdapter adapter = new ArrayAdapter(this, Guardian.Resource.Id.spinner, gdm.Porgram_names);
combo.Adapter = adapter;
}
catch (Exception exc)
{

}


My app crashes and this message appears (try catch block dosen't catch it):


Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f050000 type #0x12 is not valid


When i comment this line:
combo.Adapter=adapter;
the program doesn't crash.

Any idea what is wrong?

Answer Source

The second parameter to ArrayAdapter needs to be a Resource.Layout resource that determines how each row in the List is displayed.

It cannot be a Resource.Id value.

In other words, you've found the Spinner by an ID, then you need to say how you'd like to show the items within that Spinner using a layout.

For example,

new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, gdm.Porgram_names);