Bonjour,
J'aimerais lancer un script php en ouvrant une URL à partir de mon code java android.
J'ai ces erreurs :
Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 01-13 13:33:32.593: E/AndroidRuntime(2594): FATAL EXCEPTION: main 01-13 13:33:32.593: E/AndroidRuntime(2594): Process: com.example.whoissam, PID: 2594 01-13 13:33:32.593: E/AndroidRuntime(2594): android.os.NetworkOnMainThreadException 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145) 01-13 13:33:32.593: E/AndroidRuntime(2594): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 01-13 13:33:32.593: E/AndroidRuntime(2594): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236) 01-13 13:33:32.593: E/AndroidRuntime(2594): at java.net.InetAddress.getAllByName(InetAddress.java:214) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.example.whoissam.MainActivity$1.onClick(MainActivity.java:75) 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.view.View.performClick(View.java:4424) 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.view.View$PerformClick.run(View.java:18383) 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.os.Handler.handleCallback(Handler.java:733) 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.os.Handler.dispatchMessage(Handler.java:95) 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.os.Looper.loop(Looper.java:137) 01-13 13:33:32.593: E/AndroidRuntime(2594): at android.app.ActivityThread.main(ActivityThread.java:4998) 01-13 13:33:32.593: E/AndroidRuntime(2594): at java.lang.reflect.Method.invokeNative(Native Method) 01-13 13:33:32.593: E/AndroidRuntime(2594): at java.lang.reflect.Method.invoke(Method.java:515) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 01-13 13:33:32.593: E/AndroidRuntime(2594): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 01-13 13:33:32.593: E/AndroidRuntime(2594): at dalvik.system.NativeStart.main(Native Method)
Si quelqu'un sait d'où vient l'erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 try { URL myURL = new URL("http://www.brieg-web.fr/insert_user.php?prenom=camarche"); URLConnection myURLConnection = myURL.openConnection(); myURLConnection.connect(); } catch (MalformedURLException e) { // new URL() failed // ... } catch (IOException e) { // openConnection() failed // ... }
Merci d'avance
Partager