When testing out my app on a phone, I got an out of memory error, and after some research, I found that it's due to my inappropriate usage of Bitmaps. Initially, I would declare a bitmap as such:
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.image_name);
From the log, I saw that the error stems from that. So, I read around and tried using an extra parameter, options, as such:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Then declaring the bitmap...
image = BitmapFactory.decodeResource(getResources(), R.drawable.image_name, options);
When running this, I don't get the out of memory error anymore, but I do receive a null pointer exception when trying to use the bitmaps, if its trying to draw them to my canvas, or calling .getWidth() and .getHeight() on them.
I'm having a hard time trying to fix this and some feedback would be much appreciated.
Error Log:
01-27 18:47:42.597: E/AndroidRuntime(15698): java.lang.NullPointerException
01-27 18:47:42.597: E/AndroidRuntime(15698): at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1083)
01-27 18:47:42.597: E/AndroidRuntime(15698): at android.graphics.Canvas.drawBitmap(Canvas.java:1139)
01-27 18:47:42.597: E/AndroidRuntime(15698): at com.mascal.petele.Game$OurView.drawMenu(Game.java:654)
01-27 18:47:42.597: E/AndroidRuntime(15698): at com.mascal.petele.Looping.run(Looping.java:34)
At Game.java:654 the line of code is:
c.drawBitmap(background, 0, 0, null);
This is the first occurrence of the usage of a bitmap, and happens for each other usage as well.