我有一个适配器,可将图像加载到视图中。它运行得很好,除了当我通过在列表视图上快速上下滚动来测试ListView时,我得到了“画布尝试使用回收的位图”。但是,我从未调用bitmap.recycle,因为我正在使用图像加载器。该错误并没有告诉我错误发生的位置。我的猜测是适配器会自动回收位图,因为我没有进行手动调用。这个问题不是很一致,但是如果我真的尝试的话,我可以重新创建它。是什么导致此问题,或者如何找到它?

这是堆栈跟踪。

11-26 11:01:41.131    1124-1124/com.android.wallfly E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.android.wallfly, PID: 1124
java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@432bc210
        at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1084)
        at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:844)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:496)
        at android.widget.ImageView.onDraw(ImageView.java:1058)
        at android.view.View.draw(View.java:15304)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.view.View.getDisplayList(View.java:14193)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.view.View.draw(View.java:15307)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.view.View.draw(View.java:15307)
        at android.widget.FrameLayout.draw(FrameLayout.java:472)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.View.draw(View.java:15018)
        at android.view.ViewGroup.drawChild(ViewGroup.java:3298)
        at android.widget.ListView.drawChild(ListView.java:3393)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3135)
        at android.widget.AbsListView.dispatchDraw(AbsListView.java:2918)
        at android.widget.ListView.dispatchDraw(ListView.java:3388)
        at android.view.View.draw(View.java:15307)
        at android.widget.AbsListView.draw(AbsListView.java:5184)
        at android.view.View.getDisplayList(View.java:14198)
        at android.view.View.getDisplayList(View.java:14240)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3272)
        at android.view.View.getDisplayList(View.java:14135)
        at android.view.View.getDisplayList(View.java:14240)


这是ImageLoader信息

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
            .threadPriority(Thread.NORM_PRIORITY - 2)
            .denyCacheImageMultipleSizesInMemory()
            .memoryCache(new WeakMemoryCache())
            .diskCacheFileNameGenerator(new Md5FileNameGenerator())
            .tasksProcessingOrder(QueueProcessingType.LIFO)
            .writeDebugLogs() // Remove for release app
            .build();

            options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisc(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .resetViewBeforeLoading(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
                .build();

最佳答案

您的ImageLoader显然正在做一些回收。

请参阅Android trying to use a recycled bitmap, not in my codeCanvas: trying to use a recycled bitmap android.graphics.Bitmap in android以更好地了解问题。

如何修复它取决于您的实现(代码)和“ imageloader”。
发布一些代码或StackTrace可能会有所帮助。

关于android - 位图回收错误,没有位图回收调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27155120/

10-13 04:57