NullPointerException in handleStopActivity — No reference to my code in stack trace

前端 未结 5 741
别跟我提以往
别跟我提以往 2020-12-28 17:31

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

相关标签:
5条回答
  • 2020-12-28 17:59

    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().

    0 讨论(0)
  • 2020-12-28 18:02

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

    NullPointerException on onSaveInstanceState with AndroidFragments

    0 讨论(0)
  • 2020-12-28 18:03

    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.

    0 讨论(0)
  • 2020-12-28 18:05

    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.

    0 讨论(0)
  • 2020-12-28 18:11

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

    0 讨论(0)
提交回复
热议问题