java.net.UnknownHostException: Unable to resolve host "images.liqucn.com": No address associated wit

时间:2022-09-03 21:51:08

报错log:

03-07 15:34:38.645: W/System.err(8731): java.net.UnknownHostException: Unable to resolve host “images.liqucn.com”: No address associated with hostname
03-07 15:34:38.655: W/System.err(8731): at java.net.InetAddress.lookupHostByName(InetAddress.java:426)
03-07 15:34:38.655: W/System.err(8731): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
03-07 15:34:38.655: W/System.err(8731): at java.net.InetAddress.getAllByName(InetAddress.java:220)
03-07 15:34:38.655: W/System.err(8731): at libcore.net.http.HttpConnection.(HttpConnection.java:71)
03-07 15:34:38.655: W/System.err(8731): at libcore.net.http.HttpConnection.(HttpConnection.java:50)
03-07 15:34:38.655: W/System.err(8731): at libcore.net.http.HttpConnection Address.connect(HttpConnection.java:351)030715:34:38.655:W/System.err(8731):atlibcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)030715:34:38.655:W/System.err(8731):atlibcore.net.http.HttpConnection.connect(HttpConnection.java:128)030715:34:38.665:W/System.err(8731):atlibcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)030715:34:38.665:W/System.err(8731):atlibcore.net.http.HttpEngine.connect(HttpEngine.java:303)030715:34:38.665:W/System.err(8731):atlibcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)030715:34:38.665:W/System.err(8731):atlibcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)030715:34:38.665:W/System.err(8731):atlibcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)030715:34:38.665:W/System.err(8731):atlibcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)030715:34:38.665:W/System.err(8731):atcom.example.duandianxuchuan.MainActivity 2.run(MainActivity.java:78)
03-07 15:34:38.665: W/System.err(8731): at java.lang.Thread.run(Thread.java:856)
03-07 15:34:38.680: W/System.err(8731): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
03-07 15:34:38.685: W/System.err(8731): at libcore.io.Posix.getaddrinfo(Native Method)
03-07 15:34:38.685: W/System.err(8731): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
03-07 15:34:38.685: W/System.err(8731): at java.net.InetAddress.lookupHostByName(InetAddress.java:411)
03-07 15:34:38.685: W/System.err(8731): … 15 more

代码是:conn.getResponseCode()

在android开发的时候经常会遇到这个错误,一般来说,造成这种错误的最普遍情况有两种:

1.android设备网络连接没打开,例如3G网络和WIFI网络

 所以,如果遇到这种错误时,请先查看网络是否已正常连接.

2.Manifest文件没有标明网络访问权限

 如果确认网络已经正常连接并且还是出这种错误的话,那么请看下你的Manifest文件是否标明应用需要网络访问权限,如果没标明的话,也访问不了网络,也会造成这种情况的.

 //网络访问权限

转载自:http://blog.csdn.net/w250shini11/article/details/8646859