我有一個微調,其工作正常,當我通過微調在數據庫中插入值,但是當我從數據庫中獲取值並將索引傳遞給微調它也可以,但是當我點擊它時更改它給出的錯誤Java空指針異常的值。請幫助我。微調異常在點擊選擇
array_spinner=new String[4];
array_spinner[0]= sing.gs.getApplicator1();
array_spinner[1]= sing.gs.getApplicator2();
array_spinner[2]= sing.gs.getApplicator3();
array_spinner[3]= sing.gs.getApplicator4();
app = (Spinner) findViewById(R.id.spnr_app);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item, array_spinner);
app.setAdapter(adapter);
//singleton check
if (sing.savedRecord)
{
getSetting();
}
getSetting方法
private void getSetting()
{
try
{
app.setSelection(Integer.valueOf(sing.gs.getApplicator_name()));
datePicker.setText(sing.gs.getSpray_date().toString());
}
catch (Exception e)
{
Log.e("Retrieve Error", e.toString());
e.printStackTrace();
}
}
logcat的
05-16 17:32:58.511: E/AndroidRuntime(910): FATAL EXCEPTION: main
05-16 17:32:58.511: E/AndroidRuntime(910): java.lang.NullPointerException
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:376)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:332)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:328)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.AbsListView.obtainView(AbsListView.java:1409)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.ListView.onMeasure(ListView.java:1127)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.View.measure(View.java:8313)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.View.measure(View.java:8313)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
05-16 17:32:58.511: E/AndroidRuntime(910): at com.android.internal.widget.WeightedLinearLayout.onMeasure(WeightedLinearLayout.java:60)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.View.measure(View.java:8313)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.View.measure(View.java:8313)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.View.measure(View.java:8313)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.os.Handler.dispatchMessage(Handler.java:99)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.os.Looper.loop(Looper.java:123)
05-16 17:32:58.511: E/AndroidRuntime(910): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-16 17:32:58.511: E/AndroidRuntime(910): at java.lang.reflect.Method.invokeNative(Native Method)
05-16 17:32:58.511: E/AndroidRuntime(910): at java.lang.reflect.Method.invoke(Method.java:507)
05-16 17:32:58.511: E/AndroidRuntime(910): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-16 17:32:58.511: E/AndroidRuntime(910): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-16 17:32:58.511: E/AndroidRuntime(910): at dalvik.system.NativeStart.main(Native Method)
後堆棧跟蹤和微調項點擊全碼。 – user370305
我沒有做任何微調項目點擊,我使用它的默認行爲,因爲我用「.getSelectedItemPosition」來獲取數據,好吧我正在用logcat更新它 – Ishtiaq
在這裏發佈完整的代碼並詳細解釋.. –