ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

error setting localhost on android

asked 2012-04-13 03:41:31 -0500

rosdai gravatar image

I'm trying to use this line to set localhost on Android

String localhost = InetAddressFactory.newNonLoopback().getHostAddress();
nodeConfiguration = NodeConfiguration.newPublic(localhost, masterUri);

then the following error occurred. If I set localhost to the android Ip directly, for example String localhost = "", the program is able to run.

E/AndroidRuntime(5551): FATAL EXCEPTION: main
E/AndroidRuntime(5551): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dsi.ant.antplusdemo/com.dsi.ant.antplusdemo.ANTPlusDemo}: java.lang.NullPointerException
E/AndroidRuntime(5551):     at
E/AndroidRuntime(5551):     at
E/AndroidRuntime(5551):     at$1500(
E/AndroidRuntime(5551):     at$H.handleMessage(
E/AndroidRuntime(5551):     at android.os.Handler.dispatchMessage(
E/AndroidRuntime(5551):     at android.os.Looper.loop(
E/AndroidRuntime(5551):     at
E/AndroidRuntime(5551):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(5551):     at java.lang.reflect.Method.invoke(
E/AndroidRuntime(5551):     at$
E/AndroidRuntime(5551):     at
E/AndroidRuntime(5551):     at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(5551): Caused by: java.lang.NullPointerException
E/AndroidRuntime(5551):     at org.ros.node.NodeConfiguration.copyOf(
E/AndroidRuntime(5551):     at DefaultNodeMainExecutor.execute(
E/AndroidRuntime(5551):     at org.ros.node.DefaultNodeMainExecutor.execute(
E/AndroidRuntime(5551):     at com.dsi.ant.antplusdemo.ANTPlusDemo.connectmaster(
E/AndroidRuntime(5551):     at com.dsi.ant.antplusdemo.ANTPlusDemo.onCreate(
E/AndroidRuntime(5551):     at
E/AndroidRuntime(5551):     at
E/AndroidRuntime(5551):     ... 11 more

Strangely, sometimes, for no reason, this line would work. but after a while, the same problem occurs again.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-04-16 10:21:54 -0500

damonkohler gravatar image

This could be related to your network connection. If you do not have a non-loopback address available (for example, when your device has no network connection), InetAddressFactory.newNonLoopback() will return null.

The only safe way to handle this is to check the result for null.

edit flag offensive delete link more


I don't think so, because i'm able to link to my roscore on PC using a fixed localhost. the network shouldn't be any problem. this is still confusing me

rosdai gravatar image rosdai  ( 2012-04-24 04:36:39 -0500 )edit

I suggest debugging into the code to see where null is being returned.

damonkohler gravatar image damonkohler  ( 2012-04-25 07:51:06 -0500 )edit

Question Tools


Asked: 2012-04-13 03:41:31 -0500

Seen: 527 times

Last updated: Apr 16 '12