gpt4 book ai didi

java - Android:无法处理 UnknownHostException [使用 Retrofit 2、okhttp3、rxandroid 2]

转载 作者:行者123 更新时间:2023-12-02 13:32:49 27 4
gpt4 key购买 nike

我有一个 Android 应用程序,它已经投入生产一段时间了。我收到了一份发给 Firebase 的致命报告(日志如下),但我不清楚下次如何避免这种情况。

我在这里找到了类似的堆栈跟踪java.net.UnknownHostException Unable to resolve host "accounts.google.com": No address associated with hostname while inserting rows in bigquery但他们能够解决这个问题:

<uses-permission android:name="android.permission.INTERNET" />

但这不是我的情况。

对于网络通信,我使用:

  • 改造2
  • 确定http 3
  • 用于 Retrofit 2 的 rxjava2 适配器

使用此设置,所有错误都会在 rx 订阅的 onError 函数中结束。我在所有 HTTP 调用中处理 UnknownHostException,但即使我没有处理,它也应该将非致命报告为最坏的情况。

我不知道如何重现这个错误。堆栈跟踪不是很有帮助,因为它没有将我指向我的应用程序的任何位置。

任何有关如何重现该错误的想法以及任何其他见解都将非常感激。

这是堆栈跟踪:

Exception java.net.UnknownHostException: Unable to resolve host "rest.mywebsite.com": No address associated with hostname
java.net.InetAddress.lookupHostByName (InetAddress.java:470)
java.net.InetAddress.getAllByNameImpl (InetAddress.java:252)
java.net.InetAddress.getAllByName (InetAddress.java:215)
okhttp3.Dns$1.lookup (Dns.java)
okhttp3.internal.connection.RouteSelector.hasNext (RouteSelector.java)
<OR>.connectFailed (RouteSelector.java)
<OR>.resetNextProxy (RouteSelector.java)
<OR>.resetNextInetSocketAddress (RouteSelector.java)
<OR>.getHostString (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.nextProxy (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.next (RouteSelector.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java)
<OR>.stripBody (CacheInterceptor.java)
<OR>.maybeCache (CacheInterceptor.java)
<OR>.cacheWritingResponse (CacheInterceptor.java)
<OR>.combine (CacheInterceptor.java)
<OR>.isEndToEnd (CacheInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java)
<OR>.cookieHeader (BridgeInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RetryAndFollowUpInterceptor.cancel (RetryAndFollowUpInterceptor.java)
<OR>.setCallStackTrace (RetryAndFollowUpInterceptor.java)
<OR>.intercept (RetryAndFollowUpInterceptor.java)
<OR>.createAddress (RetryAndFollowUpInterceptor.java)
<OR>.recover (RetryAndFollowUpInterceptor.java)
<OR>.isRecoverable (RetryAndFollowUpInterceptor.java)
<OR>.followUpRequest (RetryAndFollowUpInterceptor.java)
<OR>.sameConnection (RetryAndFollowUpInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.logging.HttpLoggingInterceptor.setLevel (HttpLoggingInterceptor.java)
<OR>.intercept (HttpLoggingInterceptor.java)
<OR>.isPlaintext (HttpLoggingInterceptor.java)
<OR>.bodyEncoded (HttpLoggingInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java)
okhttp3.RealCall$AsyncCall.execute (RealCall.java)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
java.lang.Thread.run (Thread.java:818)

Caused by android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
libcore.io.Posix.android_getaddrinfo (Posix.java)
libcore.io.ForwardingOs.android_getaddrinfo (ForwardingOs.java:55)
java.net.InetAddress.lookupHostByName (InetAddress.java:451)
java.net.InetAddress.getAllByNameImpl (InetAddress.java:252)
java.net.InetAddress.getAllByName (InetAddress.java:215)
okhttp3.Dns$1.lookup (Dns.java)
okhttp3.internal.connection.RouteSelector.hasNext (RouteSelector.java)
<OR>.connectFailed (RouteSelector.java)
<OR>.resetNextProxy (RouteSelector.java)
<OR>.resetNextInetSocketAddress (RouteSelector.java)
<OR>.getHostString (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.nextProxy (RouteSelector.java)
okhttp3.internal.connection.RouteSelector.next (RouteSelector.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.StreamAllocation.newStream (StreamAllocation.java)
<OR>.findHealthyConnection (StreamAllocation.java)
<OR>.findConnection (StreamAllocation.java)
<OR>.streamFinished (StreamAllocation.java)
<OR>.codec (StreamAllocation.java)
<OR>.deallocate (StreamAllocation.java)
<OR>.streamFailed (StreamAllocation.java)
<OR>.acquire (StreamAllocation.java)
okhttp3.internal.connection.ConnectInterceptor.intercept (ConnectInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.cache.CacheInterceptor.intercept (CacheInterceptor.java)
<OR>.stripBody (CacheInterceptor.java)
<OR>.maybeCache (CacheInterceptor.java)
<OR>.cacheWritingResponse (CacheInterceptor.java)
<OR>.combine (CacheInterceptor.java)
<OR>.isEndToEnd (CacheInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.BridgeInterceptor.intercept (BridgeInterceptor.java)
<OR>.cookieHeader (BridgeInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RetryAndFollowUpInterceptor.cancel (RetryAndFollowUpInterceptor.java)
<OR>.setCallStackTrace (RetryAndFollowUpInterceptor.java)
<OR>.intercept (RetryAndFollowUpInterceptor.java)
<OR>.createAddress (RetryAndFollowUpInterceptor.java)
<OR>.recover (RetryAndFollowUpInterceptor.java)
<OR>.isRecoverable (RetryAndFollowUpInterceptor.java)
<OR>.followUpRequest (RetryAndFollowUpInterceptor.java)
<OR>.sameConnection (RetryAndFollowUpInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.logging.HttpLoggingInterceptor.setLevel (HttpLoggingInterceptor.java)
<OR>.intercept (HttpLoggingInterceptor.java)
<OR>.isPlaintext (HttpLoggingInterceptor.java)
<OR>.bodyEncoded (HttpLoggingInterceptor.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.internal.http.RealInterceptorChain.request (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.proceed (RealInterceptorChain.java)
<OR>.sameConnection (RealInterceptorChain.java)
okhttp3.RealCall.getResponseWithInterceptorChain (RealCall.java)
okhttp3.RealCall$AsyncCall.execute (RealCall.java)
okhttp3.internal.NamedRunnable.run (NamedRunnable.java)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1113)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:588)
java.lang.Thread.run (Thread.java:818)

手机网络断开,发生在 Android 6.0.1 上。

最佳答案

该问题导致嵌套 Rx 调用。当我取消订阅一个 Rx 调用时,嵌套的调用仍然存在并导致崩溃。

关于java - Android:无法处理 UnknownHostException [使用 Retrofit 2、okhttp3、rxandroid 2],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43135211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com