執行圖片異步任務,學習連接:
http://schimpf.es/asynctask-for-image-download/
在代碼中:
ImageView im1 = (ImageView) findViewById(R.id.image);
ImageDownloadTask imageD = new ImageDownloadTask(im1);
imageD.execute(e.mediumLabel);
結果報出的錯誤:
06-19 15:22:23.480: E/AndroidRuntime(18376): FATAL EXCEPTION: AsyncTask #2
06-19 15:22:23.480: E/AndroidRuntime(18376): java.lang.RuntimeException: An error occured while executing doInBackground()
06-19 15:22:23.480: E/AndroidRuntime(18376): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-19 15:22:23.480: E/AndroidRuntime(18376): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.lang.Thread.run(Thread.java:856)
06-19 15:22:23.480: E/AndroidRuntime(18376): Caused by: java.lang.NullPointerException: println needs a message
06-19 15:22:23.480: E/AndroidRuntime(18376): at android.util.Log.println_native(Native Method)
06-19 15:22:23.480: E/AndroidRuntime(18376): at android.util.Log.e(Log.java:231)
06-19 15:22:23.480: E/AndroidRuntime(18376): at com.example.beerportfoliopro.ImageDownloadTask.doInBackground(ImageDownloadTask.java:42)
06-19 15:22:23.480: E/AndroidRuntime(18376): at com.example.beerportfoliopro.ImageDownloadTask.doInBackground(ImageDownloadTask.java:1)
06-19 15:22:23.480: E/AndroidRuntime(18376): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-19 15:22:23.480: E/AndroidRuntime(18376): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
給你個建議,當報錯時最好看這些:Caused by: java.lang.NullPointerException: println
NullPointerException這個意思是空指針報錯。沒有傳對對象。。。