My android app gives the following when I try to run it….
The application OxfordApp has stopped unexpectedly. Please try again.
My code is as follows:
package oxfordlife.com.android;
public class OxfordApp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.array_name, android.R.layout.simple_spinner_item );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
Spinner s = (Spinner)findViewById(R.id.spinner1);
s.setAdapter(adapter);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I am populating the spinner from the string.xml file as follows:
<string-array name="array_name">
<item>Array Item One</item>
<item>Array Item Two</item>
<item>Array Item Three</item>
</string-array>
The app works fine if I dont try to bind the data to the spinner but as soon as I try to populate it the error is thrown. Can anyone see what I may be doing wrong here ??
Do
In the beginning of your onCreate method, before trying to access spinner1.