Throwing exception although right IP used

霸气de小男生 提交于 2019-12-25 02:11:12

问题


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;
}

}

Although I am entering the right router IP it keeps throwing exception as if I am entering a wrong IP and the message "not connected" pops out And I am not connecting the router to the internet

The stack trace is:

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)

回答1:


Print the stack trace from the exception you're passed. Are you sure the exception does not stem from the resolution of the InetSocketAddress? Try it again with various other hostnames, like "localhost" and perhaps an IPv4 equivalent address.




回答2:


Have you tried adding Internet Permission in the manifest file, if not add

<uses-permission android:name="android.permission.INTERNET" />


来源:https://stackoverflow.com/questions/20512296/throwing-exception-although-right-ip-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!