开发者

Android application crashes when populating spinner

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开发者_如何学JAVA 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 countriesArray has 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 CountryItem objects.

Other than that, the only difference I see is that you pass the context as a final variable, but I don't know if this causes the error. Try to pass just this and see if it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜