安卓的UnknownHostException Facebook的SDK [英] Android UnknownHostException Facebook SDK

查看:199
本文介绍了安卓的UnknownHostException Facebook的SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的情况。我的应用程序运行正常,并能建立连接与网址。但几个小时离开了应用程序运行后,突然Facebook的请求是给我下面的错误。

  10月9号至26号:01:25.175:W / System.err的(252):的java.net.UnknownHostException:主机是没有得到解决:xyz.com:80
10月9号至26日:01:25.175:W / System.err的(252):在java.net.Socket.connect(Socket.java:1037)
9月26号10:01:25.175:W / System.err的(252):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
9月26号10:01:25.175:W / System.err的(252):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
9月26号10:01:25.175:W / System.err的(252):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
9月26号10:01:25.175:W / System.err的(252):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
9月26号10:01:25.175:W / System.err的(252):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
9月26号10:01:25.175:W / System.err的(252):在org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1051)
10月9号至26日:01:25.175:W / System.err的(252):在java.net.URL.openStream(URL.java:653)
 

此错误上的应用程序和仿真器发生了两个。当我注销我的应用程序,并重新连接到Facebook的连接重新工作。

我要指出的:当我建立我自己的服务器连接,就不会出现问题

此错误是由行如下面...

  mAsyncFacebookRunner.request(FQL,paramaters,
                新FQLRequestListener());
 

解决方案

的java.net.UnknownHostException 通常是指一台主机的IP地址无法解析,虽然实际的原因可能会有所不同逐案。如果code正确执行(无论使用的API,HttpURLConnection的或DefaultHttpClient的),并且它还是发生了间歇性,它很可能在古老的Andr​​oid系统相关的DNS缓存和TTL管理中的错误:

发行7904:Android不支持TTL和缓存DNS结果10分钟

这是固定由于Android 4.1,请参阅 InetAddress类的API文档<多余的注意事项/一>:

  

DNS缓存

     

在的Andr​​oid 4.0(冰淇淋三明治)和更早版本,DNS缓存是由两个InetAddress类和C库,这意味着DNS的TTL无法正确兑现执行。在以后的版本中,缓存由图书馆和DNS的TTL很荣幸的C单独完成的。

有关旧的Andr​​oid版本,Android的建议调整Java级别DNS属性 networkaddress.cache.ttl networkaddress.cache.negative.ttl ,看到的JavaDoc中的<一个href="http://$c$c.metager.de/source/xref/android/4.0.3/libcore/luni/src/main/java/java/net/InetAddress.java"相对=nofollow>老源$ C ​​$ C

  / **
 * ......
 *
 *&LT; H4&GT; DNS缓存&LT; / H4&GT;
 *&LT; P&gt;在Android上,地址缓存600秒(10分钟),在默认情况下。失败的查找是
 *缓存10秒钟。底层C库或操作系统可以缓存的时间更长,但你可以控制
 *在Java级别的缓存与通常的{@ codenetworkaddress.cache.ttl}和
 * {@ codenetworkaddress.cache.negative.ttl}系统属性。这些被解析为整数。
 *秒,其中特殊值0表示不缓存,-1表示永远缓存的数字。
 *
 * ......
 * /
 

相关讨论:

尝试调整这两个属性,看看是否有什么差别,如果你的目标在一个古老的Andr​​oid版本。

Here is the situation. My app runs fine, and is able to establish connections with URLs. BUT after a few hours of leaving the app running, all of a sudden the Facebook requests are giving me the following error.

09-26 10:01:25.175: W/System.err(252): java.net.UnknownHostException: Host is unresolved: xyz.com:80
09-26 10:01:25.175: W/System.err(252):  at java.net.Socket.connect(Socket.java:1037)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
09-26 10:01:25.175: W/System.err(252):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1051)
09-26 10:01:25.175: W/System.err(252):  at java.net.URL.openStream(URL.java:653)

This error happens both on the app and the emulator. When I logout of my app and reconnect to Facebook the connections work again.

I should note: When I establish connections with my own server, no problem occurs.

This error is caused by lines such as the following...

mAsyncFacebookRunner.request("fql", paramaters,
                new FQLRequestListener());

解决方案

java.net.UnknownHostException generally means the IP address of a host could not be resolved, although the actual cause may vary case-by-case. If the code is implemented properly (regardless of which API you use, HttpUrlConnection or DefaultHttpClient) and it is still happened intermittently, it is very likely a bug in old Android system related to DNS caching and TTL management:

Issue 7904: Android does not support TTL and caches DNS result for 10 minutes

This is fixed since Android 4.1, see the extra notes in InetAddress API Doc:

DNS caching

In Android 4.0 (Ice Cream Sandwich) and earlier, DNS caching was performed both by InetAddress and by the C library, which meant that DNS TTLs could not be honored correctly. In later releases, caching is done solely by the C library and DNS TTLs are honored.

For old Android version, Android suggests adjust Java level DNS properties networkaddress.cache.ttl and networkaddress.cache.negative.ttl, see JavaDoc in old source code:

/**
 * ... ...
 *
 * <h4>DNS caching</h4>
 * <p>On Android, addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are
 * cached for 10 seconds. The underlying C library or OS may cache for longer, but you can control
 * the Java-level caching with the usual {@code "networkaddress.cache.ttl"} and
 * {@code "networkaddress.cache.negative.ttl"} system properties. These are parsed as integer
 * numbers of seconds, where the special value 0 means "don't cache" and -1 means "cache forever".
 *
 * ... ...
 */

Related discussion:

Try adjusting those two properties and see if that makes any difference, if you are targeting on an old Android version.

这篇关于安卓的UnknownHostException Facebook的SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆