スピナーにデータを入力しようとする前にダイアログを一度ポップアップさせることができたので、スピナーに情報をロードするときにエラーが発生したと思います。ボタンをクリックすると、ダイアログが起動し、次のエラーで強制終了します。
06-27 18:46:28.101: E/AndroidRuntime(26120): FATAL EXCEPTION: main
06-27 18:46:28.101: E/AndroidRuntime(26120): java.lang.IllegalStateException: Could not execute method of the activity
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.view.View$1.onClick(View.java:3609)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.view.View.performClick(View.java:4102)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.view.View$PerformClick.run(View.java:17126)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.os.Handler.handleCallback(Handler.java:615)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.os.Handler.dispatchMessage(Handler.java:92)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.os.Looper.loop(Looper.java:155)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.app.ActivityThread.main(ActivityThread.java:5536)
06-27 18:46:28.101: E/AndroidRuntime(26120): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 18:46:28.101: E/AndroidRuntime(26120): at java.lang.reflect.Method.invoke(Method.java:511)
06-27 18:46:28.101: E/AndroidRuntime(26120): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
06-27 18:46:28.101: E/AndroidRuntime(26120): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
06-27 18:46:28.101: E/AndroidRuntime(26120): at dalvik.system.NativeStart.main(Native Method)
06-27 18:46:28.101: E/AndroidRuntime(26120): Caused by: java.lang.reflect.InvocationTargetException
06-27 18:46:28.101: E/AndroidRuntime(26120): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 18:46:28.101: E/AndroidRuntime(26120): at java.lang.reflect.Method.invoke(Method.java:511)
06-27 18:46:28.101: E/AndroidRuntime(26120): at android.view.View$1.onClick(View.java:3604)
06-27 18:46:28.101: E/AndroidRuntime(26120): ... 11 more
06-27 18:46:28.101: E/AndroidRuntime(26120): Caused by: java.lang.NullPointerException
06-27 18:46:28.101: E/AndroidRuntime(26120): at com.example.beerportfoliopro.TasteTags.addTaste(TasteTags.java:71)
onclick メソッドのボタンがあるページは次のとおりです。
public class TasteTags extends Activity {
BeerData e;
String[] tastes = {
"Dwight D. Eisenhower",
"John F. Kennedy",
"Lyndon B. Johnson",
"Richard Nixon",
"Gerald Ford",
"Jimmy Carter",
"Ronald Reagan",
"George H. W. Bush",
"Bill Clinton",
"George W. Bush",
"Barack Obama"
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tastetag_page);
//get beer data
Intent intent = getIntent();
Bundle b = intent.getExtras();
e = b.getParcelable("myBeerObject");
TextView beerTitle = (TextView) findViewById(R.id.beerTitleTaste);
beerTitle.setText(e.beerName + " Taste Profile");
String url = myURL;
url = url + "b=" +e.beerId;
//async task to get beer taste tag percents
new GetTasteJSON(this).execute(url);
}
public void addTaste(View v){
// custom dialog
final Dialog dialog = new Dialog(this);
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.taste_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
dialog.setContentView(R.layout.add_taste_dialog);
dialog.setTitle("Add Taste");
dialog.show();
}
}