Skip to content
MtrXTools

java.net.UnknownHostException

Java couldn't resolve the hostname

Seen in Java, Android, Spring, Maven, Gradle, Kafka clients

DNS lookup for the hostname failed, so Java never opened a connection.

Common causes

  • A typo in the hostname or a URL passed where a host was expected.
  • The record does not exist, or only resolves inside a VPN or private network.
  • No working DNS in the container, emulator or device.
  • A negative lookup cached by the JVM (networkaddress.cache.negative.ttl).

How to fix it

  1. Check the exact hostname in the exception message.
  2. Look up the name from the same machine (getent hosts or nslookup).
  3. Check the container, VPN or device DNS settings.
  4. Restart the JVM after fixing DNS if the failure was cached.
Look up the name

Got a different message? Paste it into the error explainer.

Related errors

All 32 Languages & runtimes errors