新手求教,报错LOG如下:
java.net.SocketException: No route to host
at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:440)
at java.net.Socket.connect(Socket.java:1013)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
报错的代码段:
URL url = new URL(validateUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET"); // 请求格式
conn.connect();//在这报错
手机移动网开着呢,<uses-permission android:name="android.permission.INTERNET" /> 也加上了。
出现这种情况一般是什么问题啊?
URL 手机 Android Java 移动开发
------解决方案--------------------
网络不通..你的Server IP对于手机来说,访问不到.
------解决方案--------------------
new Thread() {
public void run() {
URL url;
try {
url = new URL("http://www.actinet.cn/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();