Parcel.readException 将对象传递给远程服务

发布于 2024-09-28 07:37:45 字数 706 浏览 4 评论 0原文

我编写了一个远程服务,客户端可以使用 Android 提供的 IPC 常用机制进行登录,并且绑定似乎可以工作。当我去调用一个必须将对象作为参数传递的方法时,问题就出现了,因为我得到了这个“奇怪的”异常:

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)

它似乎是从 .aidl 文件生成的代理类中抛出的。

更奇怪的是,对象似乎被正确传递,但可能有问题。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2024-10-05 07:37:45

我也遇到过这个问题,经过一番摸索后发现了问题所在。我将发布我的解决方案,以防它帮助其他人发现在同一条船上漂流。

首先,除非您在远程服务上启用调试,否则调试远程线程在 Eclipse 中不起作用。为此,我需要运行应用程序并在仅绑定服务的第一个活动中放置一个断点,一旦服务启动并运行,我在 Eclipse 中打开 DDMS 窗口,选择远程线程并按下调试按钮。现在可以跳回 java 窗口并将断点添加到远程服务中并触发它们。

从那里我发现我的问题实际上是我试图在远程进程中的存根函数中操作空指针对象,这反过来又在它返回的结果中注入了 nullpointerException 的包裹异常,看起来就像这个原始问题所问的那样关于。

我的解决方案只是在使用它之前测试该对象不为空:)

即我添加了“if”语句,正如您在存根函数的实现中所期望的那样...

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

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() 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文