Caused by: android.os.NetworkOnMainThreadException
04-25 13:15:52.362: E/AndroidRuntime(20900): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.io.IoBridge.connect(IoBridge.java:112)
04-25 13:15:52.362: E/AndroidRuntime(20900): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
04-25 13:15:52.362: E/AndroidRuntime(20900): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
04-25 13:15:52.362: E/AndroidRuntime(20900): at java.net.Socket.connect(Socket.java:842)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
04-25 13:15:52.362: E/AndroidRuntime(20900): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
04-25 13:15:52.362: E/AndroidRuntime(20900): at java.net.URLConnection.getContent(URLConnection.java:190)
04-25 13:15:52.362: E/AndroidRuntime(20900): at java.net.URL.getContent(URL.java:447)
04-25 13:15:52.362: E/AndroidRuntime(20900): at biz.xicom.printvintage.HomeScreen$2.run(HomeScreen.java:199)
04-25 13:15:52.362: E/AndroidRuntime(20900): at android.app.Activity.runOnUiThread(Activity.java:4644)
04-25 13:15:52.362: E/AndroidRuntime(20900): at biz.xicom.printvintage.HomeScreen.setview(HomeScreen.java:193)
04-25 13:15:52.362: E/AndroidRuntime(20900): at biz.xicom.printvintage.HomeScreen.onCreate(HomeScreen.java:58)
04-25 13:15:52.362: E/AndroidRuntime(20900): at android.app.Activity.performCreate(Activity.java:5104)
04-25 13:15:52.362: E/AndroidRuntime(20900): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-25 13:15:52.362: E/AndroidRuntime(20900): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
コード
for (int i = 0; i < image_list.size(); i++) {
LayoutInflater layoutInflator = HomeScreen.this.getLayoutInflater();
LinearLayout childlayout = (LinearLayout) layoutInflator.inflate(
R.layout.image_text_web_services_inflate, mPager, false);
im = (ImageView) childlayout.findViewById(R.id.image_web_service);
t = (TextView) childlayout.findViewById(R.id.text_web_service);
t.setText(HomeScreen.detail_list.get(i));
final int j=i;
runOnUiThread(new Runnable() {
public void run(){
try {
Bitmap bitmap = BitmapFactory
.decodeStream((InputStream) new URL(
HomeScreen.image_list.get(j))
.getContent());
im.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
mPager.addView(childlayout);
}
以下のリンクを読みました:
さらに読み込む - ビュー階層を作成した元のスレッドのみがそのビューにアクセスできます
Android - 原因: android.view.ViewRootImpl$CalledFromWrongThreadException
誰もが言った
メイン UI スレッドを更新しようとしているか、AsyncTask がそれを許可していません。
次に、画像を更新または表示できる場所。
AsyncTaskも試してください。 ループに実装する方法よりも