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.
I hope it helps.
java.net.UnknownHostException: Unable to resolve host url: No address associated with hostname
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.
How can I manually trigger a Unable to resolve host Exception on an Android Device
You can trigger an UnknownHostException
by spelling the host name incorrectly. The cause of the error won't be the same, but at least you'll get the same class of exception.
Out there "in the wild" this exception can happen for a number of reasons, including:
- device loses connection to the network during or shortly before host name resolution
- device connects to a captive portal that intercepts DNS requests or is not connected to the Internet
- DNS request fails or times out for any other random reason
DNS request timeouts are a particularly insidious problem. They are difficult to reproduce. The default timeout is way too long, longer than users are willing to wait, and there's no way to change it. Developers have to resort to hacks like this: Can I set the getaddrinfo timeout in Android for DefaultHttpClient?
java.net.UnknownHostException: Unable to resolve host : No address associated with hostname
What is the value of TIMEOUT? is in seconds or milliseconds?
* @param timeout the time, in milliseconds, before the call aborts
* @return a {@code boolean} indicating if the address is reachable.
* @throws IOException if a network error occurs
* @throws IllegalArgumentException if {@code timeout} is negative.
* @since 1.5
*/
public boolean isReachable(int timeout) throws IOException {
return isReachable(null, 0, timeout);
}
TIMEOUT is a generic name so be sure that is imported correctly.
Unable to resolve host URL here No address associated with host name
You probably don't have the INTERNET
permission. Try adding this to your AndroidManifest.xml
file, right before </manifest>
:
<uses-permission android:name="android.permission.INTERNET" />
Note: the above doesn't have to be right before the </manifest>
tag, but that is a good / correct place to put it.
Note: if this answer doesn't help in your case, read the other answers!
java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname)
I think you are testing it in an Emulator. Since the service is in a real server, I prefer using a real device. Also, using emulator is OK. But some emulator shows weird behavior with real web services. Try using a different emulator, preferably a newly created one.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
So, you have a
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
java.net.ConnectException: Connection refused
I'm quoting from this answer which also contains a step-by-step MySQL+JDBC tutorial:
If you get a
SQLException: Connection refused
orConnection timed out
or a MySQL specificCommunicationsException:
, then it means that the DB isn't reachable at all. This can have one or more of the following causes:
Communications link failure
- IP address or hostname in JDBC URL is wrong.
- Hostname in JDBC URL is not recognized by local DNS server.
- Port number is missing or wrong in JDBC URL.
- DB server is down.
- DB server doesn't accept TCP/IP connections.
- DB server has run out of connections.
- Something in between Java and DB is blocking connections, e.g. a firewall or proxy.
To solve the one or the other, follow the following advices:
- Verify and test them with
ping
.- Refresh DNS or use IP address in JDBC URL instead.
- Verify it based on
my.cnf
of MySQL DB.- Start the DB.
- Verify if mysqld is started without the
--skip-networking option
.- Restart the DB and fix your code accordingly that it closes connections in
finally
.- Disable firewall and/or configure firewall/proxy to allow/forward the port.
See also:
- How should I connect to JDBC database / datasource in a servlet based application?
- Is it safe to use a static java.sql.Connection instance in a multithreaded system?
Related Topics
Unobtrusive Way to Combine and Compress JavaScript/CSS for Java/Spring/Maven Applications
How to Clear the (Css) Visited History of an Android Webview
Selenium Webdriver - Getcssvalue() Method
Dynamically Add CSS Stylesheets in Javafx
How to Set -Fx-Max-Width to Use_Pref_Size in Javafx CSS
How to Get the Selected Index of a Radiogroup in Android
How to Set Background Color of an Activity to White Programmatically
How to Manage Cookies with Httpclient in Android And/Or Java
Getextractedtext on Inactive Inputconnection Warning on Android
Android Project Using Httpclient --> Http.Client (Apache), Post/Get Method
Rxjava Android How to Use the Zip Operator
Map.Clear() VS New Map:Which One Will Be Better
Registering a Headset Button Click with Broadcastreceiver in Android
How to Convert 24 Hr Format Time in to 12 Hr Format
Android Studio - No Jvm Installation Found
Failed to Resolve: Com.Google.Firebase:Firebase-Core:16.0.1