in my map i try to show hight quality markers, so i use xml markers from an svg files instead of using low png pictures, so to do that i convert the xml to bitmap with:
public BitmapDescriptor vectorToBitmap(Context context, @DrawableRes int id) 
{
    Drawable vectorDrawable = ContextCompat.getDrawable(context, id);
    int h = Objects.requireNonNull(vectorDrawable).getIntrinsicHeight();
    int w = Objects.requireNonNull(vectorDrawable).getIntrinsicWidth();
    vectorDrawable.setBounds(0, 0, w, h);
    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bm);
    vectorDrawable.draw(canvas);
    BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bm);
    return bitmapDescriptor;
}
then i call this methode by:
BitmapDescriptor marker = vectorToBitmap(getActivity(),R.drawable.pin_work);
everything work fine in many devices, but sometimes i get this error
Context.getDrawable(int) on a null object reference
how can i fix this specially with LG smartphones?
thank you
 
     
    