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

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 = "192.168.13.111", 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 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
E/AndroidRuntime(5551):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
E/AndroidRuntime(5551):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(5551):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime(5551):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(5551):     at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(5551):     at android.app.ActivityThread.main(ActivityThread.java:3835)
E/AndroidRuntime(5551):     at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(5551):     at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(5551):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
E/AndroidRuntime(5551):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
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(NodeConfiguration.java:78)
E/AndroidRuntime(5551):     at DefaultNodeMainExecutor.execute(DefaultNodeMainExecutor.java:110)
E/AndroidRuntime(5551):     at org.ros.node.DefaultNodeMainExecutor.execute(DefaultNodeMainExecutor.java:134)
E/AndroidRuntime(5551):     at com.dsi.ant.antplusdemo.ANTPlusDemo.connectmaster(ANTPlusDemo.java:506)
E/AndroidRuntime(5551):     at com.dsi.ant.antplusdemo.ANTPlusDemo.onCreate(ANTPlusDemo.java:414)
E/AndroidRuntime(5551):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(5551):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
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
1

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

Comments

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

Stats

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

Seen: 549 times

Last updated: Apr 16 '12