Search code examples
javaandroidconnectionhttpconnection

android app crashes on reboot java.net.UnknownHostException: Unable to resolve host


when i restart my device it crashes my app, it is hard to debug and what i search i said it say to add internet permission which i had in my manifest i can't figure it out what to do, can anyone please guide me.

02-24 17:37:05.750: I/System.out(5201): onErrorResponse:com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "eventiapp.com": No address associated with hostname
    02-24 17:37:05.750: W/System.err(5201): com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "eventiapp.com": No address associated with hostname
    02-24 17:37:05.750: W/System.err(5201):     at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:133)
    02-24 17:37:05.750: W/System.err(5201):     at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)
    02-24 17:37:05.750: W/System.err(5201): Caused by: java.net.UnknownHostException: Unable to resolve host "eventiapp.com": No address associated with hostname
    02-24 17:37:05.755: W/System.err(5201):     at java.net.InetAddress.lookupHostByName(InetAddress.java:424)
    02-24 17:37:05.755: W/System.err(5201):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
    02-24 17:37:05.755: W/System.err(5201):     at java.net.InetAddress.getAllByName(InetAddress.java:214)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
    02-24 17:37:05.755: W/System.err(5201):     at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
    02-24 17:37:05.755: W/System.err(5201):     at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:227)
    02-24 17:37:05.755: W/System.err(5201):     at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:210)
    02-24 17:37:05.755: W/System.err(5201):     at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:106)
    02-24 17:37:05.755: W/System.err(5201):     at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
    02-24 17:37:05.755: W/System.err(5201):     ... 1 more
    02-24 17:37:05.755: W/System.err(5201): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)
    02-24 17:37:05.760: W/System.err(5201):     at libcore.io.Posix.getaddrinfo(Native Method)
    02-24 17:37:05.770: W/System.err(5201):     at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55)
    02-24 17:37:05.770: W/System.err(5201):     at java.net.InetAddress.lookupHostByName(InetAddress.java:405)
    02-24 17:37:05.770: W/System.err(5201):     ... 18 more
    02-24 17:37:05.770: W/System.err(5201): Caused by: libcore.io.ErrnoException: getaddrinfo failed: ENETUNREACH (Network is unreachable)
    02-24 17:37:05.775: W/System.err(5201):     ... 21 more##

Solution

  • Do you check network connectivity before create an http request, as this:

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    return netInfo != null && netInfo.isConnectedOrConnecting();