开发者

Android socket throws UnknownHostException error

开发者 https://www.devze.com 2023-03-23 08:33 出处:网络
Why do I get this error... java.net.UnknownHostException: http://google.com ...when I do this in my Activity -> onCreate?

Why do I get this error...

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

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

try {
   Socket socke开发者_C百科t = 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


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消