Mon LogCat lit:
08-19 09:29:01.964: WARN/System.err(311): Java.net.SocketException: Permission denied
08-19 09:29:02.204: WARN/System.err(311): at org.Apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Native Method)
08-19 09:29:02.214: WARN/System.err(311): at org.Apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetworkSystem.Java:186)
08-19 09:29:02.214: WARN/System.err(311): at org.Apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.Java:265)
08-19 09:29:02.224: WARN/System.err(311): at Java.net.Socket.checkClosedAndCreate(Socket.Java:873)
08-19 09:29:02.224: WARN/System.err(311): at Java.net.Socket.connect(Socket.Java:1020)
08-19 09:29:02.224: WARN/System.err(311): at org.Apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.Java:62)
08-19 09:29:02.224: WARN/System.err(311): at org.Apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.Java:88)
08-19 09:29:02.224: WARN/System.err(311): at org.Apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.Java:927)
08-19 09:29:02.224: WARN/System.err(311): at org.Apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.Java:909)
08-19 09:29:02.234: WARN/System.err(311): at org.Apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.Java:1152)
08-19 09:29:02.234: WARN/System.err(311): at Java.net.URL.openStream(URL.Java:653)
08-19 09:29:02.244: WARN/System.err(311): at around.lowell.Main.onCreate(Main.Java:57)
08-19 09:29:02.244: WARN/System.err(311): at Android.app.Instrumentation.callActivityOnCreate(Instrumentation.Java:1047)
08-19 09:29:02.244: WARN/System.err(311): at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2627)
08-19 09:29:02.244: WARN/System.err(311): at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2679)
08-19 09:29:02.244: WARN/System.err(311): at Android.app.ActivityThread.access$2300(ActivityThread.Java:125)
08-19 09:29:02.244: WARN/System.err(311): at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:2033)
08-19 09:29:02.244: WARN/System.err(311): at Android.os.Handler.dispatchMessage(Handler.Java:99)
08-19 09:29:02.244: WARN/System.err(311): at Android.os.Looper.loop(Looper.Java:123)
08-19 09:29:02.244: WARN/System.err(311): at Android.app.ActivityThread.main(ActivityThread.Java:4627)
08-19 09:29:02.254: WARN/System.err(311): at Java.lang.reflect.Method.invokeNative(Native Method)
08-19 09:29:02.254: WARN/System.err(311): at Java.lang.reflect.Method.invoke(Method.Java:521)
08-19 09:29:02.254: WARN/System.err(311): at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:868)
08-19 09:29:02.264: WARN/System.err(311): at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:626)
08-19 09:29:02.264: WARN/System.err(311): at dalvik.system.NativeStart.main(Native Method)
Le code que j'ai récemment implémenté pour lequel il génère cette erreur dans mon Android est:
FileOutputStream fOut = null;
try {
fOut = this.openFileOutput("employeeInformation.xml", MODE_PRIVATE);
try {
InputStream is = new URL("http://totheriver.com/learn/xml/code/employees.xml").openStream();
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
fOut.write(buffer);
} catch(Exception e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Quelqu'un sait-il quel est le problème?
Ajoutez une autorisation Internet à votre manifeste:
<uses-permission Android:name="Android.permission.INTERNET"/>
Vous devez accéder à votre fichier manifeste dans votre Android puis au-dessus de la section application
à côté des autres autorisations, ajoutez: Android.permission.INTERNET
Votre manifeste devrait ressembler à ceci:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:versionCode="1"
Android:versionName="1.0" >
<uses-sdk
Android:minSdkVersion="8"
Android:targetSdkVersion="18" />
....
<uses-permission Android:name="Android.permission.INTERNET" />
...
<application
Android:allowBackup="true"
....
garder à l'esprit la valeur (Android.permission.INTERNET
) est sensible à la casse.
J'espère que cela vous fera gagner du temps.