shashi jangir
shashi jangir

Reputation: 11

java.net.UnknownHostException: Unable to resolve host No address associated with hostname

When API call from background service and mobile screen is off. Got the following error.

java.net.UnknownHostException: Unable to resolve host: No address associated with hostname W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:424) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) at java.net.InetAddress.getAllByName(InetAddress.java:214) at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)

 When API call from background service and mobile screen is off. Got the following error.
java.net.UnknownHostException: Unable to resolve host "": No address associated with hostname
W/System.err:     at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
                  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
                  at java.net.InetAddress.getAllByName(InetAddress.java:214)
                  at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
                  at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
                  at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
                  at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
                  at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
                  at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
                  at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
                  at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
                  at com.android.okhttp.internal.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:161)

Upvotes: 0

Views: 2012

Answers (1)

Sourabh Bans
Sourabh Bans

Reputation: 3134

If you haven't already done so, add the permissions to your AndroidManifest.xml file.

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

I think that's the most common cause of this UnknownHostException error message. Another possible cause is that your Internet connection is actually down.

Upvotes: 0

Related Questions