9

My app crashes sometimes on Samsung phones: "java.lang.NullPointerException" but it doesn't reference to my code anywhere. What can I do to avoid this error?

java.lang.NullPointerException
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:2476)
at android.app.ActivityThread.access$1800(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:952)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
kees0000
  • 105
  • 2
  • Is that an error occurring in the field or on your development device? try to identify the likely code path which is responsible by adding logging statements to your code. Then put that code in a try catch block catching Exception and AndroidRuntimeException and printing the stacktrace. But before doing that check the logcat again. Its likely that you are going to find another stacktrace which tells you what went wrong. – Renard Apr 25 '12 at 19:36
  • Unfortunately not, I can not reproduce this error itself. It happens mostly on Samsung phones – kees0000 Apr 25 '12 at 19:40
  • Check your onCreate(). You most likely have a bad findViewByID() in there somewhere. – SeanPONeil Apr 25 '12 at 19:36
  • not likely since the error occurs only sometimes. But i agree its likely that the problem is inside onCreate – Renard Apr 25 '12 at 19:40
  • It must be something else. I can not reproduce, but we use ACRA for Android. Thus we can see that this error is common on Samsung phones – kees0000 Apr 25 '12 at 19:42
  • do you use a cursor with startManagingCursor()?. If so check that you dont pass a null pointer into that method or else the system will try to close it at some point and you get a npe. – Renard Apr 25 '12 at 19:48
  • 2
    This should not have been closed as localized - failures on specific android models are a **common** and tricky problem in android development, often tracking back by circuitous paths to subtle programming errors / unsafe assumptions, but sometimes to errors in the android builds on the devices – Chris Stratton Apr 25 '12 at 19:54
  • 2
    @ChrisStratton So would you like me to reopen and then close as "Not A Real Question" for being incredibly broad, or "Not Constructive" because you want to compile a list of all the places where you can get an NPE? =) – casperOne Apr 25 '12 at 19:58
  • 4
    @casperOne this question is not broad. To someone familiar with android work, it's a specific example of a common type of problem, in the most tricky to debug form. Give it at least few hours to develop. (Perhaps you missed it, but the NPE is not in the application, what is null is the application itself due to a startup failure) – Chris Stratton Apr 25 '12 at 20:04
  • @ChrisStratton We don't give questions a few hours to develop on Stack Overflow; the size of the site and the velocity with which things accumulate is very high, hence the need to shut things down. You can also [ask on meta](http://meta.stackoverflow.com), if you wish to appeal or garner reopen votes. – casperOne Apr 25 '12 at 20:06
  • @kees0000 Can you edit in the entire log of the application startup? – Chris Stratton Apr 25 '12 at 20:15
  • @ChrisStratton Unfortunately not, the message is all we have. The app is based on this (feed) framework: http://code.google.com/p/libs-for-android/ – kees0000 Apr 25 '12 at 20:45
  • You need to look for the causative error/warning happening between the Intent that launched the app and the NPE reported above. It sounds like you have a log snippet from a reporting tool. Chances are you are going to need to get your hands on a device which experiences the error and run logcat yourself to get a more complete record - I know of at least one service that rents devices by the day to aid in figuring out the whole story on such spare reports. You can also review non-Java parts of your code for errors/unsafe device assumptions, particularly your xml files. – Chris Stratton Apr 25 '12 at 21:22
  • @kees0000 Any progress? The SO community really failed to address your quite valid challenge of debugging with only a limited field report to go on. – Chris Stratton May 15 '12 at 20:06
  • Unfortunately still no solution. We think it has to do with the back button on a Samsung phone. Indeed a pity that this topic is closed, a simular question is here: http://stackoverflow.com/questions/8431342/listview-random-indexoutofboundsexception-on-froyo/10351496 – kees0000 May 16 '12 at 07:55
  • Something similar happened to me with Samsung and Sony devices, the cause seems to be the way I save the state. I was putting too much information in the savedState bundle, and this was causing a `FAILED BINDER TRANSACTION`, I believe, this throws a NullPointerException like the one you mention in some devices, for example, certain Samsung models. I will write another comment as soon as I can prove this. – mdelolmo Aug 21 '12 at 14:31
  • 3
    why this question is closed? I use ACRA and get such reports too. – Alex Zaitsev Nov 20 '12 at 08:25
  • Can someone with high enough reputation vote to reopen this question? – alaeri Dec 05 '13 at 09:07

0 Answers0