我收到此错误:
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);
答案 0 :(得分:0)
我这样做是为了工作:
Spinner spinusertype = (Spinner) dialog.findViewById(R.id.spinnerUserType);
而不是这个:
Spinner spinusertype = (Spinner) findViewById(R.id.spinnerUserType);
我不知道为什么它会有所作为,因为spinnner的id是唯一的。