BringBackJiraiyaSensei
Newbie
Im trying to costumize some code from a book to fit my own purpose, however im getting this error
" Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference" in the int resID line, but im not sure why. If someone can point me in the right direction it will be greatly appreciated!
" Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference" in the int resID line, but im not sure why. If someone can point me in the right direction it will be greatly appreciated!
Code:
public Bitmap prepareBitmap(Context _context, String _bitmapName, int _pixelsPerMetre)
{
// Make a resource id from a String that is the same name as the .png
int resID = _context.getResources().getIdentifier(_bitmapName,"drawable", _context.getPackageName());
// Create the bitmap
Bitmap bitmap = BitmapFactory.decodeResource(_context.getResources(), resID);
// Scale the bitmapSheet based on the number of pixels per metre
// Multiply by the number of frames contained in the image file
// Default 1 frame
bitmap = Bitmap.createScaledBitmap(bitmap, (int) (width * animFrameCount * _pixelsPerMetre),
(int) (height * _pixelsPerMetre), false);
return bitmap;
}
Last edited by a moderator:
