-1

I am working with Bitmap in android.

In AsyncTask's doInBackgroud method I did the following code

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;
    }

from the above code the

myBitmap = new Bitmap[myKeyList.size()];

myBitmap assigned null and myKeyList.size() is not zero.

How can I resolve this? Is I anything missed?

Karthikeyan Ve
  • 2,550
  • 4
  • 22
  • 40

1 Answers1

1

myBitmap assigned null

Because you just create myBitmap Array but not added data.

You need to convert your ArrayList to Array like

 myBitmap =myKeyList.toArray(new Bitmap[myKeyList.size()]);
M D
  • 47,665
  • 9
  • 93
  • 114