0

Why do I get this error...

java.net.UnknownHostException: http://google.com

...when I do this in my Activity -> onCreate?

try {
   Socket socket = new Socket("http://google.com", 80);
} catch(Exception e) {
   Log.e(tag, e.toString());
   return;
}

And yes, I do have the Internet permission set in my manifest.

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

This is being tested on a physical Nexus S phone

3 Answers 3

5

Use www.google.com, without the http:// part.

Sign up to request clarification or add additional context in comments.

Comments

1

Is it throwing an UnknownException or UnknownHostException?

UnknownHostException means there is a problem with the hostname lookup. Try it without the "http://" and if that doesn't work, try it with the direct IP address.

Its not your app permissions that is failing, otherwise it would throw a SecurityException.

Comments

0

Socket throws an UnknownHostException - if the IP address of the host could not be determined.

Do you have Internet Access enabled? Try it with another host or with the IP and/or try restarting your phone.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.