Эй, у меня большая проблема с моим Android-приложением.В настоящее время я обновляю его, и я переключился с API 8 на API 10, и следующий блок кода больше не работает ...
URL url = new URL(PingUrl);
URLConnection Conn = url.openConnection();
Conn.setConnectTimeout(4000);
int Size = 2048;
BufferedReader input = new BufferedReader(new InputStreamReader(Conn.getInputStream()), Size);
String line = null;
while ((line = input.readLine()) != null) {
JSONObject jo = new JSONObject(line);
String timeStamp = jo.getString("timestamp");
//Log.i("Value",timeStamp);
}
input.close();
result = true;
Это приводит к сбою @ BufferedReader ... кто-нибудь получил идею?
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): FATAL EXCEPTION: main
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): java.lang.RuntimeException: Unable to start activity ComponentInfo{be.paratel.PAC/be.paratel.PAC.PACMainViewActivity}: android.os.NetworkOnMainThreadException
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.ActivityThread.access$500(ActivityThread.java:122)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.os.Looper.loop(Looper.java:132)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.ActivityThread.main(ActivityThread.java:4123)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at java.lang.reflect.Method.invoke(Method.java:491)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at dalvik.system.NativeStart.main(Native Method)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): Caused by: android.os.NetworkOnMainThreadException
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at java.net.InetAddress.lookupHostByName(InetAddress.java:477)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:277)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at java.net.InetAddress.getAllByName(InetAddress.java:249)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1038)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:523)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at be.paratel.PAC.PACMainViewActivity.pingTheApplication(PACMainViewActivity.java:245)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at be.paratel.PAC.PACMainViewActivity.ConnectionCheck(PACMainViewActivity.java:296)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at be.paratel.PAC.PACMainViewActivity.onCreate(PACMainViewActivity.java:70)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.Activity.performCreate(Activity.java:4397)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
10-19 16:46:04.814: ERROR/AndroidRuntime(2151): ... 11 more