非致命异常:java.net.UnknownHostException无法解析主机“mysite.com”:没有与主机名关联的地址

时间:2014-11-16 20:48:12

标签: java android crashlytics

我的crashLytics报告中有很多条目:

java.net.UnknownHostException: Unable to resolve host "mobile.site.com": No address associated with hostname
       at java.net.InetAddress.lookupHostByName(InetAddress.java:394)
       at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
       at java.net.InetAddress.getAllByName(InetAddress.java:214)
       at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
       at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
       at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
       at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
       at com.spmkt.mobile.action.FormDAO.uploadFormsWithoutPics(SourceFile:70)
       at com.spmkt.mobile.action.FormDAO.uploadFormsWithPics(SourceFile:171)
       at com.spmkt.mobile.BaseActivity.sync_total(SourceFile:274)
       at com.spmkt.mobile.BaseActivity$1.run(SourceFile:170)
       at java.lang.Thread.run(Thread.java:856)

我想当我的服务器关闭,或者当android检测到互联网连接时出现,但是质量非常差,无法连接。

防止这种例外是否可行???

2 个答案:

答案 0 :(得分:0)

您可以在代码周围使用try-catch块。

https://docs.oracle.com/javase/tutorial/essential/exceptions/try.html

答案 1 :(得分:0)

使用以前版本的lib(.jar)文件.in async-http-1.4.9给出了同样的错误。但1.4.7版本的代码工作正常