Android JB 4.1.2 を搭載した Samsung Galaxy S2 でサンプル アプリケーションを実行しています。アプリケーションを実行すると、正常に実行され、地震データのリストが取得され、検索も正常に機能します。
しかし、環境設定で何かを変更するとすぐに、自動更新を false に設定するなどして、アプリケーションを閉じようとすると、エラー メッセージが表示されます。
Unfortunately, Earthquake has stopped
ADB Logcat からのメッセージを以下に示します。
11-30 16:04:30.103: ERROR/AndroidRuntime(4295): FATAL EXCEPTION: main
java.lang.RuntimeException: Failure delivering result o activity {com.paad.earthquake/com.paad.earthquake.Earthquake}: android.os.NetworkOnMainThreadException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3267)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3310)
at android.app.ActivityThread.access$1100(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1254)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4906)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
at java.net.InetAddress.getAllByName(InetAddress.java:214)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
at com.paad.earthquake.EarthquakeListFragment.refreshEarthquakes(EarthquakeListFragment.java:90)
at com.paad.earthquake.Earthquake.onActivityResult(Earthquake.java:92)
at android.app.Activity.dispatchActivityResult(Activity.java:5192)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3263)
... 11 more
このエラーを修正する方法を教えてください。よろしく クラム・マジード