我正在动态创建Spinners和其他小部件。该应用程序在水平或垂直视图中工作正常但如果我从一个翻转到另一个,应用程序崩溃说下面的微调器具有空指针异常和强制关闭后发生
我不知道问题究竟是什么,我假设整个活动是从onCreate From logs开始创建的,那么为什么它会得到Null Pointer? (补充说它在一个视图中工作正常)
以下是我动态设置的代码
sku[lineNo].setOnItemSelectedListener (onSpinnerClick);
这是onItemSelectedLister For spinner
OnItemSelectedListener onSpinnerClick = new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v,int position, long id) {
Log.v("This","onclick"+parent.getSelectedItem()+" view "+v.getId()+" pos "+ //
position+" id "+id+" parentid "+parent.getId()); // Error happens in this Line
switch(parent.getId()){
// do something
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
此处出现Log Cat错误消息(前几行)
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.app.Activity.CurActivity$2.onItemSelected(CurActivity.java:1379)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
at android.widget.AdapterView.selectionChanged(AdapterView.java:847)
at android.widget.AdapterView.checkSelectionChanged(AdapterView.java:970)
at android.widget.AdapterView.handleDataChanged(AdapterView.java:952)
at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:179)
at android.view.View.measure(View.java:8171)
我希望这些信息足够。在此先感谢,只是一些线索将有所帮助