在Android应用中使用spinner绑定adapter的时候出错(待解决)?
错误详细信息:
09-20 21:57:56.617: ERROR/AndroidRuntime(317): Caused by: java.lang.NullPointerException
09-20 21:57:56.617: ERROR/AndroidRuntime(317): at com.gqk.android.register.SolderRegister.onCreate(SolderRegister.java:49)
09-20 21:57:56.617: ERROR/AndroidRuntime(317): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 21:57:56.617: ERROR/AndroidRuntime(317): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-20 21:57:56.617: ERROR/AndroidRuntime(317): ... 11 more
源码:
private String areaStr; private String[] areaList = {"服饰","电器","首饰","点卡、话费充值","内衣"};
//private List<string> spinnerStrings;
private ArrayAdapter<String> areaAdapter;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
findViews();
userMessage = (UserMessage)getApplicationContext();
/*spinnerStrings = new ArrayList<String>();
for(int i=0;i < areaList.length;i++){
spinnerStrings.add(areaList[i]);
}*/
areaAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,areaList);
areaAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_solderregisterarea.setAdapter(areaAdapter);//这里就是错误信息里的 SolderRegister.java:49
//setImage();
setListeners();
}
private EditText editText_solderregisteraccount;
private Spinner spinner_solderregisterarea;
private ImageView imageView_solderregistervalidatecode;
private Button button_solderswitchimage,button_soldercomfirmregister;
private CheckBox checkBox_solderagree;
private void findViews(){
editText_solderregisteraccount = (EditText)findViewById(R.id.editText_solderregisteraccount);
spinner_solderregisterarea = (Spinner)findViewById(R.id.spinner_solderregisterarea);
imageView_solderregistervalidatecode = (ImageView)findViewById(R.id.imageView_solderregistervalidatecode);
button_solderswitchimage = (Button)findViewById(R.id.button_solderswitchimage);
button_soldercomfirmregister = (Button)findViewById(R.id.button_soldercomfirmregister);
checkBox_solderagree = (CheckBox)findViewById(R.id.checkBox_solderagree);
}
求解?
以解决!其实错误不在这个代码本身,而在其它地方出错,我的组里有人跟我报的错一模一样,但都是其它地方代码写错了。。。。