2 annbnncnnd AnnBnnCnnD 于 2013.06.20 16:16 提问

异步任务加载图片报错

执行图片异步任务,学习连接:

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)

3个回答

u011114585
u011114585   2013.06.20 21:17
已采纳

给你个建议,当报错时最好看这些:Caused by: java.lang.NullPointerException: println

NullPointerException这个意思是空指针报错。没有传对对象。。。

cj6585256
cj6585256   2013.06.20 16:42

根据你给的学习连接看
public class ImageDownloadTask extends AsyncTask 继承关系

imageD.execute(e.mediumLabel);
e.mediumLabel这个是什么东西.此处可以传递Url根据下面方法加载图片就好了,可以传递多个参数

imageD.execute(String... params)里面传递的是可变参数
protected Bitmap doInBackground(String... params) {
String url = params[0];//假如第一个参数传递的是url的话

//TODO downLoadImage

Kakalapa1986
Kakalapa1986   2013.06.20 17:29

在调用日志Log.e时,没有传递有效的字符串,其中一个是空的。看ImageDownloadTask line 42

Csdn user default icon
上传中...
上传图片
插入图片