How do I begin to troubleshoot errors like this? I get them from time to time and I have no idea what to do with them. I thought I was getting pretty good at decoding stack traces, but this one leaves me baffled.
java.lang.NullPointerException
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
at android.widget.AbsListView.obtainView(AbsListView.java:1315)
at android.widget.ListView.makeAndAddView(ListView.java:1727)
at android.widget.ListView.fillDown(ListView.java:652)
at android.widget.ListView.fillSpecific(ListView.java:1284)
at android.widget.ListView.layoutChildren(ListView.java:1558)
at android.widget.AbsListView.onLayout(AbsListView.java:1147)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
at android.view.View.layout(View.java:7035)
at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
at android.view.View.layout(View.java:7035)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Have I uncovered an android bug? I’d include some code, but I have no idea what code to include. It could be anything.
Probably not.
No, it cannot. The stack trace points out that there is a problem in
ArrayAdapter. Either you are creating anArrayAdapterthat has an issue, or you are creating something else (e.g., anAlertDialog) that itself is creating anArrayAdapter. There can only be so many places in your code where this occurs, and presumably there are significant portions of your code that have nothing to do withArrayAdapter.Next, you can see that the exception occurs in
createViewFromResource(). Just from the method name and the exception, the most likely problem should have sprung to mind: you supplied an invalid layout resource ID in theArrayAdapterconstructor.Note that the “invalid layout resource ID” may not be your fault. Whenever you encounter a resource-related error in Android development, clean your project (Project > Clean from the Eclipse main menu, or
ant cleanfrom the command line) and try again. If the problem goes away, life is good. If the problem persists, in this case, take a good look at yourArrayAdapterconstructor.You are welcome to examine the source code to
ArrayAdapterandcreateViewFromResource()if that helps. The link points to the most recent version of that class, though you can use the “Branches” tab to find one that corresponds to whatever version of Android you happen to be running. Sometimes, if you are running on hardware, the line numbers will not match, because the device manufacturer tinkered with the class, but given the method name, you can still find the general area where the problem lies. In this case, there are relatively few things that could reasonably raise aNullPointerException, and so the most likely case is still that you (or the build tools) supplied an invalid layout resource ID.