benkc benkc - 1 year ago 96
Android Question

NullPointerException (etc) from Parcel.readException

Exceptions that look like this are confusing:

at android.os.Parcel.readException(
at android.os.Parcel.readException(
at com.yourpackage.ipc.IYourClass$Stub$Proxy.yourMethod(
at com.yourpackage.ipc.YourClassShim.yourMethod(

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.

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):

RuntimeException("Unknown exception code: " + code + " msg " + msg);

But what's causing these?

Answer Source

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download