androidandroid-wifiandroid-4.2-jelly-bean

java.net.UnknownHostException: Unable to resolve host "<url>": No address associated with hostname


I am 100% sure that the phone has internet connection. I can browser websites and the connection works. Nonetheless, from my app, I see this error:

java.net.UnknownHostException: Unable to resolve host "<url>": No address associated with hostname

In the source code, the URL that I am providing works from the web browser, I can visit it.

The solution at java.net.UnknownHostException: Unable to resolve host "<url>": No address associated with hostname and End of input at character 0 of suggests to double check WiFi or disconnect and then reconnect to the WiFi network. I tried doing that and even restarting the phone. I have internet access for sure.

The interesting thing is that everything works on Android 6.x and above. This bug is happening to my app only in Android 4.x and 5.x.

UPDATE 1:

The code for the URL that I am trying to reach from the app:

public static final String MY_URL = CORE_URL + "Panama/products/json_index/";

When I visit the URL stored in MY_URL, I see this in the web browser, a JSON response:

{"result":"Success","Cities":[{"name":"Panama","slug":"panama-city"},{"name":"Colombia","slug":"Bogota"}]}

The URL works and I have WiFi. Everything works on Android 6.x and above. Weird that only Android 4.x and 5.x fail.

UPDATE 2:

This is how I reference the URL later in the code:

Util.requestGetData(Util.MY_URL, this, ResponseListener.REQUEST_MY_CITIES_LIST);

I also use this:

@Override
public void onResponse(final Response r, final int rid) {
    ...
    docment = new JSONObject(r.getData());
    ...
}

The problem happens when I use r.getData().

UPDATE 3:

If from the phone with Android 4.x I visit the URL, I get this:

{"result":"Success","Cities":[{"name":"Panama","slug":"panama-city"},{"name":"Colombia","slug":"Bogota"}]}

The URL works and I have internet access and the WiFi is fine from what I see because I can browse websites and everything is normal. Maybe intermittent WiFi? To me everything looks fine with the WiFi and the internet access is fine. When I use r.getData() from Android 6.x and above the app works without problems. What could be happening in Android 4.x and 5.x that I get this error. Something weird is that it used to work before but in the last few weeks it suddenly stopped working without me changing the code at all.

UPDATE 4:

If in my code I use "http://www.google.com" as the URL instead, I am getting a different error in the Android Studio Logcat but in the app exactly the same problem:

07-01 19:28:58.791 28351-28399/com.myapp D/tag: http://www.google.com
07-01 19:28:59.171 28351-28351/com.myapp D/OpenGLRenderer: Enabling debug mode 0
07-01 19:28:59.171 28351-28351/com.myapp D/ProgressBar: updateDrawableBounds: left = 0
07-01 19:28:59.171 28351-28351/com.myapp D/ProgressBar: updateDrawableBounds: top = 0
07-01 19:28:59.171 28351-28351/com.myapp D/ProgressBar: updateDrawableBounds: right = 72
07-01 19:28:59.171 28351-28351/com.myapp D/ProgressBar: updateDrawableBounds: bottom = 72
07-01 19:28:59.231 28351-28407/com.myapp I/dalvikvm: Could not find method android.content.Context.checkSelfPermission, referenced from method com.urbanairship.analytics.EventApiClient.getLocationPermission
07-01 19:28:59.231 28351-28407/com.myapp W/dalvikvm: VFY: unable to resolve virtual method 138: Landroid/content/Context;.checkSelfPermission (Ljava/lang/String;)I
07-01 19:28:59.231 28351-28407/com.myapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x000c
07-01 19:28:59.431 28351-28351/com.myapp E/ViewRootImpl: sendUserActionEvent() mView == null
07-01 19:28:59.471 28351-28351/com.myapp W/InputMethodManager: Ignoring onBind: cur seq=57, given seq=56

UPDATE 5:

I changed the value in MY_URL to "http://www.google.com", as you can see in UPDATE 4 above. Now I changed it back to the URL that I had before, and now the error that I am seeing is different but the app still fails the same way. This is the error now:

07-01 19:36:31.931 28645-28645/com.myapp D/OpenGLRenderer: Enabling debug mode 0
07-01 19:36:31.931 28645-28645/com.myapp D/ProgressBar: updateDrawableBounds: left = 0
07-01 19:36:31.931 28645-28645/com.myapp D/ProgressBar: updateDrawableBounds: top = 0
07-01 19:36:31.931 28645-28645/com.myapp D/ProgressBar: updateDrawableBounds: right = 72
07-01 19:36:31.931 28645-28645/com.myapp D/ProgressBar: updateDrawableBounds: bottom = 72
07-01 19:36:32.011 28645-28705/com.myapp I/dalvikvm: Could not find method android.content.Context.checkSelfPermission, referenced from method com.urbanairship.analytics.EventApiClient.getLocationPermission
07-01 19:36:32.011 28645-28705/com.myapp W/dalvikvm: VFY: unable to resolve virtual method 138: Landroid/content/Context;.checkSelfPermission (Ljava/lang/String;)I
07-01 19:36:32.011 28645-28705/com.myapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x000c
07-01 19:36:32.031 28645-28698/com.myapp W/System.err: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at com.android.org.conscrypt.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:146)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-01 19:36:32.031 28645-28698/com.myapp W/System.err:     at com.myapp.Util.Util$1.run(Util.java:242)
07-01 19:36:32.041 28645-28698/com.myapp W/System.err:     at java.lang.Thread.run(Thread.java:841)
07-01 19:36:32.251 28645-28645/com.myapp E/ViewRootImpl: sendUserActionEvent() mView == null
07-01 19:36:32.301 28645-28645/com.myapp W/InputMethodManager: Ignoring onBind: cur seq=60, given seq=59

UPDATE 6:

Now I am consistently seeing this error and java.net.UnknownHostException: Unable to resolve host "<url>": No address associated with hostname is never appearing again in the Android Studio Logcat:

07-02 09:30:15.468 9350-9391/com.myapp W/System.err: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at com.android.org.conscrypt.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:146)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:93)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at com.myapp.Util.Util$1.run(Util.java:242)
07-02 09:30:15.478 9350-9391/com.myapp W/System.err:     at java.lang.Thread.run(Thread.java:841)
07-02 09:30:15.628 9350-9350/com.myapp E/ViewRootImpl: sendUserActionEvent() mView == null
07-02 09:30:15.668 9350-9350/com.myapp W/InputMethodManager: Ignoring onBind: cur seq=77, given seq=76

Maybe the real problem is the SSL certificate and it has nothing to do with WiFi problems or the availability of the URL that I am using?


Solution

  • I guess I need to close this question now because it has become directly related to this other question: javax.net.ssl.SSLPeerUnverifiedException: No peer certificate on Android 4.x and 5.x. So the fix to that other question will become the fix to this question as well.