尝试使用异步任务加载图像时出错

时间:2013-06-19 20:50:36

标签: android android-asynctask android-imageview

我试图实现我从这里得到的图像异步任务:

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)

1 个答案:

答案 0 :(得分:3)

当您调用日志记录Log.e时,您没有传入有效的字符串,其中一个为空。见ImageDownloadTask line 42