2

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.

MrGibbage
  • 2,644
  • 5
  • 39
  • 50

4 Answers4

3

Have I uncovered an android bug?

Probably not.

It could be anything.

No, it cannot. The stack trace points out that there is a problem in ArrayAdapter. Either you are creating an ArrayAdapter that has an issue, or you are creating something else (e.g., an AlertDialog) that itself is creating an ArrayAdapter. 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 with ArrayAdapter.

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 the ArrayAdapter constructor.

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 clean from 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 your ArrayAdapter constructor.

You are welcome to examine the source code to ArrayAdapter and createViewFromResource() 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 a NullPointerException, and so the most likely case is still that you (or the build tools) supplied an invalid layout resource ID.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • You were correct. I was not manipulating my array adapter correctly (there were a couple of errors). Your analysis was spot on and very helpful. Thanks! – MrGibbage Mar 18 '12 at 15:41
0

I received such exceptions when I had problems with xml files (layouts or Manifest). It happend during application startup.

anakkin
  • 731
  • 1
  • 6
  • 21
0

Depending on your IDE, you could use the Eclipse / Intellij IDEA debugger to trace through the code and find exactly where in your Activity it's failing.

Ken Fehling
  • 2,051
  • 23
  • 32
0

In my experience, this is not an Android bug but a problem with the Android implementation on a specific device. I had a similar problem which I posted on SO a long time back - App crashing in Desire HD and there is some discussion there which might be helpful.

However, assume all devices are properly QA'ed. Apart from hardware issues (camera/sensors) , almost no device would crash for reasons other than something being wrong with your code.

Also be very careful when copy-pasting code from the web!

Community
  • 1
  • 1
Abhinav
  • 38,516
  • 9
  • 41
  • 49