Java.Net.Unknownhostexception: Unable to Resolve Host "<Url>": No Address Associated with Hostname and End of Input at Character 0 Of

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 or Connection timed out or a MySQL specific CommunicationsException:
Communications link failure
, then it means that the DB isn't reachable at all. This can have one or more of the following causes:

  1. IP address or hostname in JDBC URL is wrong.
  2. Hostname in JDBC URL is not recognized by local DNS server.
  3. Port number is missing or wrong in JDBC URL.
  4. DB server is down.
  5. DB server doesn't accept TCP/IP connections.
  6. DB server has run out of connections.
  7. 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:

  1. Verify and test them with ping.
  2. Refresh DNS or use IP address in JDBC URL instead.
  3. Verify it based on my.cnf of MySQL DB.
  4. Start the DB.
  5. Verify if mysqld is started without the --skip-networking option.
  6. Restart the DB and fix your code accordingly that it closes connections in finally.
  7. 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



Leave a reply



Submit