来自Parcel.readException的NullPointerException(等) [英] NullPointerException (etc) from Parcel.readException
问题描述
看起来像这样的异常令人困惑:
Exceptions that look like this are confusing:
FATAL EXCEPTION: main
java.lang.NullPointerException
at android.os.Parcel.readException(Parcel.java:1437)
at android.os.Parcel.readException(Parcel.java:1385)
at com.yourpackage.ipc.IYourClass$Stub$Proxy.yourMethod(IYourClass.java:488)
at com.yourpackage.ipc.YourClassShim.yourMethod(YourClassShim.java:269)
我找到了许多与此相关的问题,但是没有一个答案是如何调试".所以我在做这个问题/答案.
I found a bunch of related questions for this, but none with the answer to "how do you debug this". So I'm making this Question/Answer.
通过查看android源此处,您将看到它可能会抛出其中任何一个(NullPointerException就是我所拥有的):
By looking at the android source here and here you'll see that it can be throwing any of these (the NullPointerException is just what I had):
SecurityException(msg);
BadParcelableException(msg);
IllegalArgumentException(msg);
NullPointerException(msg);
IllegalStateException(msg);
RuntimeException("Unknown exception code: " + code + " msg " + msg);
但是是什么原因造成的?
But what's causing these?
推荐答案
这里发生的是 readException()
正在检查IPC字节流中是否存在表示发生异常的标头.如果找到一个,则抛出具有相同消息的该类型的新异常,但缺少原始堆栈跟踪.(它实际上只知道一些异常类型;其他所有内容都转换为基本的 RuntimeException
.)
What's going on here is that readException()
is checking the IPC byte stream for a header that says that an exception occurred; if it finds one, then it throws a new exception of that type, with the same message, but missing the original stack trace. (It only actually knows a few exception types; anything else gets translated into a base RuntimeException
.)
那么原始异常来自何处?好吧,实际上是 YourClass.yourMethod()
的真正实现的一部分,而不是任何可打包或IPC的代码.因此,去那里,将整个方法包装在try/catch中,并记录您所捕获的所有内容.
So where's the original exception coming from? Well, somewhere down in the guts of the real implementation of YourClass.yourMethod()
-- not in any of the parcelable or IPC code. So go there, wrap the whole method in a try/catch, and log whatever you caught.
(或在远程进程断点正常工作的情况下在此处设置断点.)
(Or set a breakpoint there if you've got remote process breakpoints working.)
这篇关于来自Parcel.readException的NullPointerException(等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!