Android: BitmapFactory.decodeResource returning null

放肆的年华 提交于 2019-11-30 18:23:30

The getResources() is a Context class method and you are not using a context in your Segment class. How does it work. You should call getApplicationContext().getResources()

You should pass the context to the Segment constructor.

public Segment(Context context, int x, int y) {
    ....
    bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.droid_1);
    ....
}

Check the resolution of your image, if its too big, the BitmapFactory.decodeResource will just return null (no exception)

make sure your image is not in drawable-v24 folder, move it to drawable folder.

this worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!