2013-03-23 46 views
2

我試圖通過消費它顯示一個圖像從web服務。井工作 罰款。如果我測試我的項目與android版本像2 - 3版本它的工作fine.But它不支持超過4.0及以上。爲什麼?無法在4.0版本以上的Android模擬器中顯示圖像?

如何解決這個問題?

以下是我的代碼,

Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(img_url).getContent()); 
imgvw.setImageBitmap(bitmap); 

logcat的

03-23 14:59:17.696: I/System.out(386): Intent { cmp=com.example.png/.tab_cameraActivity } 
03-23 14:59:17.696: I/System.out(386): LB 3 
03-23 14:59:17.716: D/AndroidRuntime(386): Shutting down VM 
03-23 14:59:17.716: W/dalvikvm(386): threadid=1: thread exiting with uncaught exception (group=0x40014760) 
03-23 14:59:17.736: E/AndroidRuntime(386): FATAL EXCEPTION: main 
03-23 14:59:17.736: E/AndroidRuntime(386): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.png/com.example.png.tab_cameraActivity}: android.os.NetworkOnMainThreadException 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1577) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:130) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:342) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:680) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabHost.setCurrentTab(TabHost.java:349) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:149) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:556) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.view.View.performClick(View.java:3100) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.view.View$PerformClick.run(View.java:11644) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.Handler.handleCallback(Handler.java:587) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.Handler.dispatchMessage(Handler.java:92) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.Looper.loop(Looper.java:126) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.ActivityThread.main(ActivityThread.java:3997) 
03-23 14:59:17.736: E/AndroidRuntime(386): at java.lang.reflect.Method.invokeNative(Native Method) 
03-23 14:59:17.736: E/AndroidRuntime(386): at java.lang.reflect.Method.invoke(Method.java:491) 
03-23 14:59:17.736: E/AndroidRuntime(386): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 
03-23 14:59:17.736: E/AndroidRuntime(386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 
03-23 14:59:17.736: E/AndroidRuntime(386): at dalvik.system.NativeStart.main(Native Method) 
03-23 14:59:17.736: E/AndroidRuntime(386): Caused by: android.os.NetworkOnMainThreadException 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077) 
03-23 14:59:17.736: E/AndroidRuntime(386): at java.net.InetAddress.lookupHostByName(InetAddress.java:481) 
03-23 14:59:17.736: E/AndroidRuntime(386): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:281) 
03-23 14:59:17.736: E/AndroidRuntime(386): at java.net.InetAddress.getAllByName(InetAddress.java:249) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217) 
03-23 14:59:17.736: E/AndroidRuntime(386):  at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:153) 
03-23 14:59:17.736: E/AndroidRuntime(386): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95) 
03-23 14:59:17.736: E/AndroidRuntime(386): at com.example.png.tab_cameraActivity.getImagesDetails(tab_cameraActivity.java:73) 
03-23 14:59:17.736: E/AndroidRuntime(386): at com.example.png.tab_cameraActivity.onCreate(tab_cameraActivity.java:57) 
03-23 14:59:17.736: E/AndroidRuntime(386): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 
03-23 14:59:17.736: E/AndroidRuntime(386):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700) 
03-23 14:59:17.736: E/AndroidRuntime(386): ... 18 more 
+1

無碼,我們同樣的難題就像你會告訴你我們的代碼??? – duggu 2013-03-23 06:59:10

+0

@HCD請再次訪問我的問題。 – prabu 2013-03-23 07:01:01

+0

logcat顯示你什麼? – 2013-03-23 07:02:18

回答

1

有機會,你執行UI線程這裏面的代碼。這在Android HoneyComb及以上版本中是禁止的。您應該考慮使用AsyncTask或Android服務來執行此請求。不同的選項可以幫助你。作爲RoboSpice的貢獻者,我相信這個庫會有幫助。

+0

prabu saied他的應用在Android3上運行良好。 – hasanghaforian 2013-03-23 07:15:52

+0

我同意這一點,這也給我帶來了困擾,但這是沒有更多logcat細節的最合理的原因。 – Snicolas 2013-03-23 07:59:17

相關問題