17

I'm a bit at a loss, here. I've been seeing a steadily increasing number of these NullPointerExceptions in handleStopActivity. I suspect that the increase coinicides with the increase in 2.2 upgrades to Droid owners, though that's just a guess. I've never seen the crash myself, and the stack trace provided by the market does not mention any of the classes I've written. As such, I have no idea where to start in fixing the problem.

java.lang.NullPointerException
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3674)
at android.app.ActivityThread.access$2600(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2153)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
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)

Since I don't know the cause, I also don't know what information to provide to aid in diagnosis, so I'll give an overiew: My app is WootWatcher. It tracks Woot.com and notifies users of new items for sale. It does this by means of a service that runs in a separate process. The service and the main activity communicate with each other via aidl interface and callback. I also make use of message handlers in both the service and activity, and frequently spawn threads for expensive tasks.

Mickey
  • 943
  • 1
  • 19
  • 41
BenTobin
  • 1,201
  • 1
  • 8
  • 16

5 Answers5

2

Looking back at this 4-year old question, I realize I should be able to diagnose it, but unfortunately I can't find any version of AOSP for which these lines match up. The Droid must have used some altered version of the source that wasn't made available.

That said, Froyo's handleStopActivity() doesn't have many opportunities for a null pointer exception. The most likely one would point to Activity.finish() when the Activity has already been stopped, or is in the process of being stopped.

This usually happens when you register listeners that eventually call finish() and you don't unregister those listeners in onPause().

Sufian
  • 6,405
  • 16
  • 66
  • 120
BenTobin
  • 1,201
  • 1
  • 8
  • 16
1

How about reporting a bug to Android Project (would mandate checking if anyone else reported it) ? If no code from You is in the stack trace, that would signal a bug in the framework. Although maybe in your other code You break e.g. an unspoken contract/assumption.

KarolDepka
  • 8,318
  • 10
  • 45
  • 58
0

Refer the answer in this question. Looks like a known problem and has a solution too. Hope it helps...

NullPointerException on onSaveInstanceState with AndroidFragments

Community
  • 1
  • 1
Joseph Selvaraj
  • 2,225
  • 1
  • 21
  • 21
0

I don't know, if you're still looking for a solution, but here's what I found out. If you have found a real solution, please let me know.

I just had the same issue.. I never had that problem and without changing code, it appeared for some reason. By using google, I found the question that Joseph posted, but that doesn't seem to be exactly the same. I also found this and this. These two seem to have the same issue, but no solution.. Then I found this blog.

The author tells something about what it's from - a bug in Android. Further, it has to do with a Cursor. That didn't fix my issue, but I noticed, that I used a Cursor, a few lines before calling startActivity(someIntent); (I also called finish(), but removing that line didn't make a difference).
I tried to remove the lines that include the Cursor and suddenly it works again..
I have no idea, why it works, but it does. I just moved the code with the Cursor to my other Activity.

It's definitly not a good solution, but it works for me.

There's just one more question: Do you even use a Cursor and call startActivity(..) or something similar?

Edit:
I just found out, that I didn't fix the problem, I just didn't test enough. The Activity I started was running fine until I wanted to create the next Activity out of that Activity I started before. On starting the next Activity, my App crashes again.

Community
  • 1
  • 1
MalaKa
  • 3,734
  • 2
  • 18
  • 31
-2

Maybe try wrapping the method handleStopActivity in try-catch block and handle the error yourself, giving yourself more details and preventing "force-close" ?

KarolDepka
  • 8,318
  • 10
  • 45
  • 58
  • @BenTobin you could check out what's on ActivityThread.java:3674, it can give hints sometimes. Do the bug reports on the Play Store mention the version of Android? – Matthieu Dec 23 '13 at 18:26