java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference

前端 未结 6 1496
迷失自我
迷失自我 2021-01-06 01:16

I am trying to implement swipe to delete in RecyclerView. Everything seems to be working fine except drawing a delete icon below the item that\'s being swiped.

Thi

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-06 01:33

    The error is because of the drawable might be a Vector.

    Drawable drawable = ContextCompat.getDrawable(StreamActivity.this,R.drawable.ic_close)
    Bitmap icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(icon);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    

提交回复
热议问题