error setting localhost on android
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.