I am having problems with the emulator crashing when drawing a large image. The crash is caused by a NullPointerException when using setBounds on my drawable (so my drawable is null for some reason).
The problem only occurs in the emulator, and not if I load it on to my device (HTC Desire).
My image is a 1080×1658 px jpg. If I specify a much smaller image the problem goes away.
My code looks like this:
public class Map {
private Drawable mapImage;
public Map(Context context) {
mapImage = context.getResources().getDrawable(R.drawable.north);
}
public void render(Canvas canvas) {
mapImage.setBounds(0, 0, 1080, 1658);
mapImage.draw(canvas);
}
}
Did you check if your application’s heap is too big? You can do that with DDMS at eclipse.
An image with that size might be causing big problems.
Furthermore be sure to recycle your old bitmaps to make some space for new ones – they’re one of the most problematic things at Android.
You can increase your emulator’s heap size in the settings, too – but this doesn’t represent the reality as lots of device only have about 32 mb heap.