开发者

Parcel.readException passing an object to remote service

I wrote a remote service that the clients can log on with the usual mechanisms of IPC provided by Android and the binding seems to work. The problem arises when I go to call a method in which I have to pass an object as a parameter because I get this "curious" exception:

10-19 15:09:04.601: ERROR/AndroidRuntime(2985): FATAL EXCEPTION: main  
10-19 15:09:04.601: ERROR/AndroidRuntime(2985): java.lang.NullPointerException  
10-19 15:09:04.601: ERROR/AndroidRuntime(2985): at android.os.Parcel.readException(Parcel.java:1253)   
10-19 15:09:04.601: ERROR/AndroidRuntime(2985):at android.os.Parcel.readException(Parcel.java:1235)  
10-19 15:09:04.601: ERROR/AndroidRuntime(2985): at it.domod.commons.interfaces.DeviceManager$Stub$Proxy.sendCommand(DeviceManager.java:121)

It seems to be thrown from the proxy class generated from the .aidl file.

The more strange thing is that the object seems to be passed correctly but 开发者_如何学编程probably there is something wrong around. Any idea?


I've been encountering this issue as well and after a bit of poking around found the problem. I'm going to post my solution in case it helps others found drifting in the same boat.

Firstly debugging the remote thread doesn't work in Eclipse unless you enable debugging on the remote service. To do this I needed to run the app and put a breakpoint in my first activity that just binds the service, once the service is up and running I open the DDMS window in eclipse and select the remote thread and press the debug button. Now it's possible to jump back to the java window and add your breakpoints into the remote service and have them triggered.

From there I found my problem was actually I was trying to operate on a null pointer object in my stub function in the remote process which in turn injected a parcel exception for nullpointerexception in the result it was returning and looks like what this original question is asking about.

My solution was simply to test the object wasn't null before using it :)

i.e. I added the 'if' statement as you'd expect in the implementation of the stub function...

if( myobject != null )
{
   myobject.dosomething() 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜