Archived

This forum has been archived. Please start a new discussion on GitHub.

Servant on Android device

Hello. I'm new to programming for Android devices. I'm using Ice for Android (the latest version, 0.1.1).

I've been able to write a client application for an external servant, but I'm having trouble with hosting a servant on the Android device.

First, I briefly explain my application architecture:

- I have an Android activity that launches a Android service.
- The Android service, created by the activity, holds the communicator and the object adapter. I only initialize them on a user interface button callback.

My GUI has two buttons: one of them invokes the service to create the communicator and the object adapter. The other button creates the servant and adds it to the object adapter via my running service.

It works very good, apparently. When I try to remotely invoke the "checked cast" on the proxy hosted on my Android device, the Android's "logcat" gives me this message:
WARN/System.err(384): 600 error: Ice Acceptor Thread: 0.0.0.0:58458: acceptAsync: 
WARN/System.err(384): 0.0.0.0:58458
WARN/System.err(384): java.lang.NullPointerException
WARN/System.err(384):     at IceInternal.Network.addressesToString(Network.java:1139)
...

I have marked as synchronized the method that creates the communicator and the object adapter and the method that instanciates the servant and adds it to the adapter.

My servant's remote methods are "synchronized" too.

I was looking for a minimal example of servant hosted on a Android device, but I can't find anyone.

What are my mistakes? Thanks for your attention.

Comments

  • mes
    mes California
    Hi,

    Welcome to the forum.

    Do you have network tracing enabled? If so, try setting Ice.Trace.Network=0 to see if it works around the problem.

    Cheers,
    Mark
  • First of all, thanks for your welcome :)

    Now, about my problem.

    I just tried your suggestion, but it doesn't work... :( The log doesn't change at all.

    Is there any alternative idea?

    Thanks for your surprisingly quick reply.
  • mes
    mes California
    Hi,

    It would help us to see the complete stack trace of the NullPointerException.

    Regards,
    Mark
  • Hello.

    Excuse me for my inactivity... this was a difficult weekend :P

    Here it is: my traceback.
    04-19 08:44:36.108: WARN/System.err(6852): 19/04/10 08:44:36:107 error: Ice Acceptor Thread: 0.0.0.0:43839: acceptAsync:
    04-19 08:44:36.108: WARN/System.err(6852): 0.0.0.0:43839
    04-19 08:44:36.108: WARN/System.err(6852): java.lang.NullPointerException
    04-19 08:44:36.108: WARN/System.err(6852):     at IceInternal.Network.addressesToString(Network.java:1139)
    04-19 08:44:36.108: WARN/System.err(6852):     at IceInternal.Network.fdToString(Network.java:1115)
    04-19 08:44:36.108: WARN/System.err(6852):     at IceInternal.TcpTransceiver.<init>(TcpTransceiver.java:345)
    04-19 08:44:36.118: WARN/System.err(6852):     at IceInternal.TcpAcceptor.accept(TcpAcceptor.java:52)
    04-19 08:44:36.118: WARN/System.err(6852):     at IceInternal.IncomingConnectionFactory.acceptAsync(IncomingConnectionFactory.java:473)
    04-19 08:44:36.118: WARN/System.err(6852):     at IceInternal.IncomingConnectionFactory.access$000(IncomingConnectionFactory.java:14)
    04-19 08:44:36.118: WARN/System.err(6852):     at IceInternal.IncomingConnectionFactory$1.run(IncomingConnectionFactory.java:328)
    04-19 08:44:36.118: WARN/System.err(6852):     at java.lang.Thread.run(Thread.java:1096)
    
  • I'm working on it and I have an update on the status:

    I started debugging the IceAndroid sources, looking for where is the "null" object reference, and I have found it:

    On the method IceInternal.Network.fdToString it receives a "SelectableChannel", and from that, it makes a SocketChannel object.

    When it executes the getLocalAddress operation on this SocketChannel, it returns null, and this null is later passed to "addressesToString", who raises the NullPointerException and makes me cry :P

    I hope it helps
  • mes
    mes California
    Hi,

    Thanks for posting more details on the problem. Android's network classes are behaving differently than other JVM implementations and Ice wasn't properly working around these issues. I've posted a patch that should prevent the NullPointerException.

    Regards,
    Mark
  • mes wrote: »
    Hi,

    Thanks for posting more details on the problem. Android's network classes are behaving differently than other JVM implementations and Ice wasn't properly working around these issues. I've posted a patch that should prevent the NullPointerException.

    Regards,
    Mark

    I love you Mark :D

    I just patched, compiled and tested my application and it works!!!

    Thanks for your time and effort.

    I'm asking why your chat example works without problems and my "hello world" server (a minimal example) didn't work... is it related with the use of Glacier?
  • mes
    mes California
    I'm asking why your chat example works without problems and my "hello world" server (a minimal example) didn't work... is it related with the use of Glacier?
    Not exactly. The NullPointerException occurs in your Android server while Ice's object adapter is attempting to accept a new incoming connection. The chat demo's object adapter is not assigned any physical endpoints and therefore it cannot accept new incoming connections. Rather, it uses the createObjectAdapterWithRouter operation to create an object adapter that can only receive requests sent over bidirectional connections.

    Hope that helps,
    Mark