Android: Unknownhostexception

java.net.UnknownHostException: Unable to resolve host url: No address associated with hostname and End of input at character 0 of

I encountered this problem too, reconnecting the WiFi can solve this.

For us ,we can check if the phone can resolve the host to IP when we start application. If it cannot resolve, tell the user to check the WiFi and then exit.

android java.net.UnknownHostException: Unable to resolve host

You need to check internet connection like this:

private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

return cm.getActiveNetworkInfo() != null;
}

In manifest

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

This method actually checks if device is connected to internet(There is a possibility it's connected to a network but not to internet).

public boolean isInternetAvailable() {
try {
InetAddress ipAddr = InetAddress.getByName("google.com");
//You can replace it with your name
return !ipAddr.equals("");

} catch (Exception e) {
return false;
}
}

java.net.UnknownHostException: Unable to resolve host api.themoviedb.org

Looking at your code I found 2 issues:

  1. Your NOW_PLAYING_URL has an additional slash (themoviedb.org/3//movie/) after 3 so replace the string as

    public static final String NOW_PLAYING_URL = "https://api.themoviedb.org/3/movie/now_playing?api_key=a07e22bc18f5cb106bfe4cc1f83ad8ed";

That was the reason why your api call returns a failure.


  1. Next, the response is success but in your onSuccess() try block you are fetching data for "result" but your API response returns "results" so replace that key as below and you should not be having any issues.

    JSONArray results = jsonObject.getJSONArray("results");

Hope this helps.

Android java.net.UnknownHostException: Host is unresolved

The answer is devilishly simple: remove, then re-create your AVD (virtual device/emulator) in Eclipse. It worked for me--first time.

java.net.UnknownHostException: Unable to resolve host “url here”; No address associated with hostname

You mentioned that the url is served from your localhost (probably a desktop pc acting as a server in your home network infrastructure), is your localhost named xx2?

You should access it via IP e.g. http://192.168.1.1/.... because your android device is unaware that the name xx2 resolves to your server's ip.



Related Topics



Leave a reply



Submit