Android: BitmapFactory.decodeResource returning null

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

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

this worked for me.


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