0

我有这种类型的错误你能帮我解决它吗?或者知道这个代码我用它与其他类的其他微调器一起使用它是什么问题,所以它有点让我感到困惑,因为我有这个问题微调还是没有?她是我的日志猫

    11-16 21:56:27.841: E/AndroidRuntime(794): FATAL EXCEPTION: main
11-16 21:56:27.841: E/AndroidRuntime(794): java.lang.NullPointerException
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:291)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.widget.AbsSpinner.setAdapter(AbsSpinner.java:113)
11-16 21:56:27.841: E/AndroidRuntime(794):  at com.example.test1.MainActivity$LoadAllSection.onPostExecute(MainActivity.java:220)
11-16 21:56:27.841: E/AndroidRuntime(794):  at com.example.test1.MainActivity$LoadAllSection.onPostExecute(MainActivity.java:1)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.os.AsyncTask.finish(AsyncTask.java:417)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.os.AsyncTask.access$300(AsyncTask.java:127)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.os.Looper.loop(Looper.java:123)
11-16 21:56:27.841: E/AndroidRuntime(794):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-16 21:56:27.841: E/AndroidRuntime(794):  at java.lang.reflect.Method.invokeNative(Native Method)
11-16 21:56:27.841: E/AndroidRuntime(794):  at java.lang.reflect.Method.invoke(Method.java:521)
11-16 21:56:27.841: E/AndroidRuntime(794):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-16 21:56:27.841: E/AndroidRuntime(794):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-16 21:56:27.841: E/AndroidRuntime(794):  at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

从日志猫:

Caused by: java.lang.NullPointerException
    at com.example.test1.MainActivity$LoadAllSection.doInBackground(MainActivity.java:195)

既然你说这是第 195 行:

sectionList.add(map1);

sectionList这只是意味着null,您忘记使用以下命令对其进行初始化:

sectionList = new ArrayList<HashMap<String, String>>();

好的,对于您的新 LogCat,问题从第 220 行开始,这似乎是:

spinner2.setAdapter(adapter2); 

再次sectionList受到责备,仅当您尝试传递绑定到null数据集的适配器时才会发生此错误。

于 2012-11-16T18:57:37.043 回答