gpt4 book ai didi

android - 单击以选择微调器异常

转载 作者:行者123 更新时间:2023-11-30 04:12:28 26 4
gpt4 key购买 nike

我有一个微调器,当我通过微调器在数据库中插入值时它工作正常,但是当我从数据库中获取值并将索引传递给微调器时它也可以工作但是当我单击它以更改值时它给出错误 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();
}

获取设置方法

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();
}
}

洛格卡特

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)

最佳答案

请检查它的外观,您的 sing.gs.getApplicator1() 之一;值为 null .. 请检查所有 sing.gs.getApplicator .........

原因:转到第 394 行(您的 sdk ArrayAdepter 的第 328 行)

https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/ArrayAdapter.java

394 - text.setText(item.toString());

所以这里要么 text 可能为 null,要么 item 可能为 null。

但您使用的是内置布局,因此文本不应为空,因此项目可以为空....

关于android - 单击以选择微调器异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10618808/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com