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:
Your
NOW_PLAYING_URL
has an additional slash (themoviedb.org/3//movie/
) after 3 so replace the string aspublic 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.
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
Android: Turn Off Screen When Close to Face
How to Store Files Generated from App in "Downloads" Folder of Android
Viewpager Update Fragment on Swipe
Android Viewpager Padding/Margin Between Page Fragments
Android Serversocket Programming with Jcifs Streaming Files
How to Stop a Service Running as Foreground
How to Close Android Soft Keyboard Programmatically
Just Upgraded My Os X to Yosemite, Android Device Chooser Not Showing Device - What to Do
Audio Format for iOS and Android
Android Adding a Submenu to a Menuitem, Where Is Addsubmenu()
Notificationlistenerservice Implementation
How to Fix Android Studio Getting Stuck Executing Gradle Tasks
User Does Not Have Permission to Access This Object . Firebase Storage Android
Android Service to Check Internet Connectivity
Gradle: Add Dependency for a Specific Flavour of The Library