Fix drawable drawable=getdrawable() alternative for android programming

How to solve Call requires API level 21 (current min is 8): android.app.Activity#getDrawable error on lower API devices.

Android getdrawable() method comes with newer API 22 level and dose not work with lower api versions. If android app developer wants to user getdrawable() method into lower level api then this will show NullPointerException . So to solve this error you have to use getResources().getDrawable() at the place of getDrawable(). This method is deprecated into higher API but works fine with new and old api. So here is the complete step by step tutorial for Fix drawable drawable=getdrawable() alternative for android programming.

Fix drawable drawable=getdrawable() alternative for android programming

How to Fix drawable drawable=getdrawable() alternative for android programming.

Drawable drawable = getDrawable(R.drawable.demo_img);

Now replace getDrawable with getResources().getDrawable. Like below example.

Drawable drawable = getResources().getDrawable(R.drawable.demo_img);

Leave a Reply

Your email address will not be published. Required fields are marked *