package com.example.androidapp;
import java.net.InetSocketAddress;
import java.util.Collection;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.nxp.jip.JIPImpl;
import com.nxp.jip.PacketHandlerIPv6;
import com.nxp.jip.exception.JipException;
import com.nxp.jip.service.JenNetIPNetwork;
import com.nxp.jip.service.Node;
import com.nxp.jip.service.Service;
public class Application extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_application);
TextView display= (TextView) findViewById(R.id.textView2);
PacketHandlerIPv6 my_packet = new PacketHandlerIPv6();
JIPImpl my_jip = new JIPImpl(my_packet);
Service service =new Service(my_jip);
try{
JenNetIPNetwork network = service.createNetwork(new InetSocketAddress("fd04:bd3:80e8:2:215:8d00:32:54ff", 1873));
display.setText("Connected :)");
}
catch(JipException e){
display.setText("Not connected :(");
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.application, menu);
return true;
}
}
虽然我正在输入正确的路由器IP但它仍然会抛出异常,好像我输入了错误的IP并且弹出了“未连接”消息 而且我没有将路由器连接到互联网
堆栈跟踪是:
com.nxp.jip.exception.JipException: Timeout
at com.nxp.jip.CommandHandler.execute(CommandHandler.java:125)
at com.nxp.jip.JIPImpl.get(JIPImpl.java:129)
at com.nxp.jip.service.Service.createNetwork(Service.java:272)
at com.example.androidapp.Application.onCreate(Application.java:32)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
从您传递的异常中打印堆栈跟踪。您确定异常不是源于InetSocketAddress
的解决方案吗?再尝试使用各种其他主机名,例如“localhost”,也许还有IPv4等效地址。
答案 1 :(得分:0)
您是否尝试在清单文件中添加Internet权限,如果没有添加
<uses-permission android:name="android.permission.INTERNET" />