I found the method to read the text response from the URL and the code is compiled properly but when the app is crashing The result is the thread has started:
thread thread = new thread (new runnable) {public zero run (u} url url = new urRL ("http: //192.168. 1.10 / test try {.php "}; BufferedReader = new BufferedReader (new InputStreamReader (url.openStream ()), string line = null, while ((line = in.readLine ()) = null Accessories} in.close! ();} Grip (malformedlexceptio N e) {e.printStackTrace ();} hold (IOException e) {e.printStackTrace ();}}}); I searched for further, so when you answer, I suggest adding a reply manifest file permission:
Still I still get the same result:
06-21 15: 48: 24.597 2362-2362 /? E / AndroidRuntime: Fatal Exception: on java.net main android.os.NetworkOnMainThreadException android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork (StrictMode.java:1099) on java.net.InetAddress.lookupHostByName (InetAddress.java:391). InetAddress.getAllByNameImpl (InetAddress.java:242) java.net.InetAddress.getAllByName (InetAddress.java:220) is libcore.net.http.HttpConnection & the lt ;. Init & gt; (HttpConnection.java:71) on libcore.net. Http.HttpConnection & Lt; Init & gt; (HttpConnection.java:50) libcore.net.http.HttpConnectionPool.get on libcore.net.http.HttpConnection $ Address.connect (HttpConnection.java:351) libcore.net.http.HttpEngine) to (HttpConnectionPool.java:86 on libcore.net.http.HttpEngine.openSocketConnection (HttpEngine.java:308) on .connect libcore.net.http.HttpConnection.connect (HttpConnection.java:128) (on HttpEngine.java: 303) libcore.net.http. libcore.net.http.HttpEngine.sendSocketRequest on libcore.net.http.HttpEngine.sendRequest on HttpURLC (HttpEngine.java:282) com.smilegrp onnectionImpl.getResponse (HttpURLConnectionImpl.java:273) to (HttpEngine.java:232). libcore.net.http.HttpURLConnectionImpl.getInputStream (HttpURLConnectionImpl.java:168) com.smilegrp.ksone.MainActivity $ on $ 2 com.android on (URL.java:462) on java.net.URL.openStream on ksone.MainActivity $ 1 $ 1.run (MainActivity.java:51) at java.lang.Thread.run (Thread.java:856) at $ 1.onClick (MainActivity.java:68) On android.os.Looper.loop (Looper.java:137) on Ndroid on .internal.app.AlertController $ ButtonHandler.handleMessage (AlertController.java:166) android.os.Handler.dispatchMessage (Handler.java:99). App.ActivityThread.main (ActivityThread.java:4575) java.lang.reflect.Method.invokeNative (native resident method) at java.lang.reflect.Method.invoke (Method.java + 1111) at com.android.internal . Dalvik.system.NativeStart.main (Native Method) On / east> Why is this? I have coded in iOS first and I have to confuse and complain about Google's official document compared to Apple. : /
Exception means that you are operating the network at the UI Thread . Since you are running this inside threads , because threads calls to run () instead of on () Be sure to do> 's example
No comments:
Post a Comment