I’m trying to populate the spinner, but the application crashes on spiner.setAdapter(adapter)…
final Context c=this;
ArrayList<CountryItem> countriesArray = GetCountries1();
ArrayAdapter<CountryItem> adapter = new ArrayAdapter<CountryItem>(
c,android.R.layout.simple_spinner_item, countriesArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
final Spinner spiner=(Spinner)findViewById(R.id.spinner1);
spiner.setAdapter(adapter);
I can’t find any errors here, and eclipse debug mode does not show anything usefull…
Here is the example from google…is it so much different than my code?
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
What error do you get?
Did you check if the
countriesArrayhas elements or if it is empty?Is it working when you use, e.g., a simple string array? If yes, then the problem lies with the
CountryItemobjects.Other than that, the only difference I see is that you pass the context as a
finalvariable, but I don’t know if this causes the error. Try to pass justthisand see if it works.