0

我收到此错误:

14:03:44.170    322 hnlapp.hairdresser  ERROR   AndroidRuntime  FATAL EXCEPTION: main
14:03:44.170    322 hnlapp.hairdresser  ERROR   AndroidRuntime  java.lang.NullPointerException
14:03:44.170    322 hnlapp.hairdresser  ERROR   AndroidRuntime      at hnlapp.hairdresser.Page_Calendar.onOptionsItemSelected(Page_Calendar.java:2824)

尝试执行此操作时:

spinusertype.setAdapter(spinnerArrayAdapter);

在这段代码中:

Spinner spinusertype      =       (Spinner)  findViewById(R.id.spinnerUserType);
String[] userTypes = new String[]{"user","hairdresser","admin"};
                            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, userTypes);


                            spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                            spinusertype.setAdapter(spinnerArrayAdapter);
4

1 回答 1

0

我通过这样做使它工作:

 Spinner spinusertype            =       (Spinner)  dialog.findViewById(R.id.spinnerUserType);

而不是这个:

 Spinner spinusertype            =       (Spinner)  findViewById(R.id.spinnerUserType);

我不知道为什么它会有所作为,因为微调器的 id 是唯一的。

于 2013-01-29T12:29:11.963 回答