package com.nicotera.colton.londontransitguide;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class RoutesActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Spinner spinner = (Spinner) findViewById(R.id.route_name_spinner);
// Create an ArrayAdapter using the string array and a default
// spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.routes_array, android.R.layout.simple_spinner_item
);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item
);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
// TODO Auto-generated method stub
}
}
结果是:
12-06 23:34:28.954: E/AndroidRuntime(765): Caused by: java.lang.NullPointerException
12-06 23:34:28.954: E/AndroidRuntime(765): at com.nicotera.colton.londontransitguide.RoutesActivity.onCreate(RoutesActivity.java:22)
所以看来问题出在第 22 行,但我无法弄清楚到底出了什么问题?我是一个全新的开发人员,所以感谢所有的帮助!