在recyclerview中使用picasso加载图像时,ondraw中出现IllegalArgumentException

时间:2016-02-17 07:14:16

标签: android exception android-imageview android-recyclerview picasso

在回收站视图中使用picasso加载图像时崩溃。下面是崩溃日志。我无法找到问题的确切原因。

02-16 14:45:30.888  19543-19543/com.swen E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Cannot draw recycled bitmaps
        at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:791)
        at android.view.GLES20RecordingCanvas.drawBitmap(GLES20RecordingCanvas.java:118)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:393)
        at com.squareup.picasso.PicassoDrawable.draw(PicassoDrawable.java:96)
        at android.widget.ImageView.onDraw(ImageView.java:985)
        at android.view.View.draw(View.java:13803)
        at android.view.View.getDisplayList(View.java:12741)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.View.draw(View.java:13519)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
        at android.view.View.getDisplayList(View.java:12739)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.View.draw(View.java:13519)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
        at android.view.View.getDisplayList(View.java:12739)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.View.draw(View.java:13519)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
        at android.view.View.getDisplayList(View.java:12739)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.View.draw(View.java:13519)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
        at android.view.View.draw(View.java:13806)
        at android.widget.FrameLayout.draw(FrameLayout.java:467)
        at android.view.View.getDisplayList(View.java:12741)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.View.draw(View.java:13519)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
        at android.view.View.draw(View.java:13806)
        at android.view.View.getDisplayList(View.java:12741)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.View.draw(View.java:13519)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3019)
        at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:3588)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2883)
        at android.view.View.draw(View.java:13806)
        at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3097)
        at android.view.View.getDisplayList(View.java:12741)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)
        at android.view.View.getDisplayList(View.java:12670)
        at android.view.View.getDisplayList(View.java:12785)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3001)

适当的指导会有所帮助。

1 个答案:

答案 0 :(得分:0)

Bitmap thumbnail = Bitmap.createScaledBitmap(bmp, w, h, true)
if (!bmp.isRecycled()) {
    bmp.recycle();
}
bmp = null;