at com.example.asen.work8.MainActivity$2$1.run(MainActivity.java:65)
W/System.err: Caused by: android.system.ErrnoException: connect failed: ENETUNREACH (Network is unreachable)
65行的句子:if (conn.getResponseCode() == 200)
访问代码
private static final String PATH = "http://192.168.56.1:8080/loginService/login.jsp";
private void initListener() {
button01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Thread thread = new Thread() {
@Override
public void run() {
String name = edit1.getText().toString();
String psw = edit2.getText().toString();
String path = PATH + "?username=" + name + "&password=" + psw;
try {
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
if (conn.getResponseCode() == 200) {
InputStream is = conn.getInputStream();
String result = parseIS(is);
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString(MESSAGE_TITLE, result);
msg.setData(bundle);
handler.sendMessage(msg);
}
} catch (IOException ex) {
ex.printStackTrace();
String result = ex.toString();
Message msg = new Message();
Bundle bundle = new Bundle();
bundle.putString(MESSAGE_TITLE, result);
msg.setData(bundle);
handler.sendMessage(msg);
}
}
};
thread.start();
}
});
}
求问这个异常要怎么解决啊,ip地址我用了虚拟的ip,tomcat用这个ip也可以进去
回复讨论(解决方案)
另外我测试用的是genymotion Samsung Galaxy S7-6.0.0-API 23
网络无法访问
我换成AS自带的模拟器就可以用了。。。