我在android中使用Bitmap。
在AsyncTask的doInBackgroud方法中,我做了以下代码
protected Bitmap[] doInBackground(Object... params) {
hMap = new ConcurrentHashMap<String, ArrayList<AssetBean>>();
hMap = (ConcurrentHashMap<String, ArrayList<AssetBean>>) params[0];
myKeyList = (CopyOnWriteArrayList<String>) params[1];
if (Constants.DEBUG)
Log.i("MyKeylist", myKeyList.toString()+"myKeyList size :"+myKeyList.size());
myBitmap = new Bitmap[myKeyList.size()];
for (int i = 0; i < myKeyList.size(); i++) {
String name = myKeyList.get(i);
ArrayList<AssetBean> ab = hMap.get(name);
AssetBean b = ab.get(0);
File f = b.getThumbPath();
Bitmap bitmap;
if (null != f) {
bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
if (bitmap != null)
myBitmap[i] = bitmap;
else
myBitmap[i] = BitmapFactory.decodeResource(
mContext.getResources(),
R.drawable.brokenicon_new);
}
}
return myBitmap;
}
来自上面的代码
myBitmap = new Bitmap[myKeyList.size()];
myBitmap指定为null,myKeyList.size()不为零。
我该如何解决这个问题? 我错过了吗?
答案 0 :(得分:1)
myBitmap指定为null
因为您只是创建myBitmap
Array
但未添加数据。
您需要将ArrayList
转换为Array
myBitmap =myKeyList.toArray(new Bitmap[myKeyList.size()]);