android, httpurlconnection error

为君一笑 提交于 2019-12-22 04:24:17

问题


I'm running the following test Java script from the Android HttpURLConnection docs:

URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection)
url.openConnection();
urlConnection.connect();

Eclipse (on my Mac) is telling me there's a system error when I run this in the Android Emulator:

01-13 13:44:32.767: WARN/System.err(1382): java.net.SocketException: Permission denied

(Incidentally when I do the equivalent in Objective-C/Cocoa there's no problem at all.)

What is the problem?


回答1:


Your application is not allowed to access the network unless it has declared that its going to in the AndroidManifest.xml file, add this inside the <manifest> element.

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


来源:https://stackoverflow.com/questions/4676897/android-httpurlconnection-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!