2014-12-22 76 views
0

我正在嘗試實現一個庫,其中我以JSON文件的形式獲取圖像(大拇指)的URL。我將json解析爲ArrayLists thmb,它以字符串的形式保存縮略圖圖像的URL。 使用JSON和URL字符串,一切都很好。無法在Android中加載/顯示來自URL的圖像縮略圖

我想在圖庫視圖中加載縮略圖。爲此我試圖下載圖像並將它們保存在ArrayList中。對於相同的代碼是:

​​

類下載圖像任務:

public class DownloadImageTask extends AsyncTask <String, Bitmap, Bitmap> { 
     protected Bitmap doInBackground(String... urls) { 
      String urldisplay = urls[0]; 
      Bitmap img = null; 
      try { 
       InputStream in = new java.net.URL(urldisplay).openStream(); 
       img = BitmapFactory.decodeStream(in); 
       return img; 
      } catch (Exception e) { 
       Log.e("Error", e.getMessage()); 
       return null; 
      } 
     }   
     protected void onPostExecute(Bitmap imx) { 
        super.onPostExecute(imx); 
     } 
    } 

我不能保存位圖在ArrayList和應用得到意外停止!誰能告訴我爲什麼會發生這種情況。 的logcat中表示:基於logcat的

12-22 18:48:07.398: D/BR(6129): BITMAP RECIEVED 
12-22 18:48:08.349: D/AndroidRuntime(6129): Shutting down VM 
12-22 18:48:08.349: W/dalvikvm(6129): threadid=1: thread exiting with uncaught exception (group=0x415e9d88) 
12-22 18:48:08.359: E/AndroidRuntime(6129): FATAL EXCEPTION: main 
12-22 18:48:08.359: E/AndroidRuntime(6129): Process: com.example.videogallery, PID: 6129 
12-22 18:48:08.359: E/AndroidRuntime(6129): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.videogallery/com.example.videogallery.Stream}: java.lang.NullPointerException: println needs a message 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.ActivityThread.access$800(ActivityThread.java:144) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.os.Handler.dispatchMessage(Handler.java:102) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.os.Looper.loop(Looper.java:212) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.ActivityThread.main(ActivityThread.java:5135) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at java.lang.reflect.Method.invoke(Method.java:515) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at dalvik.system.NativeStart.main(Native Method) 
12-22 18:48:08.359: E/AndroidRuntime(6129): Caused by: java.lang.NullPointerException: println needs a message 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.util.Log.println_native(Native Method) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.util.Log.d(Log.java:139) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at com.futurristic.videogallery.Stream.onCreate(Stream.java:90) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.Activity.performCreate(Activity.java:5231) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201) 
12-22 18:48:08.359: E/AndroidRuntime(6129):  ... 11 more 

回答

0

你有NPE在thmb.get(J),因此顯示出其填充部分。

相關問題