1

I'm working on a live wallpaper and I want to have some images randomly placed on the background of a surfaceview, everything works in the emulator but when i run it on my the program crashes. I dont know how to get an actual log on my phone because its not rooted.

Below is the code:

Bitmap TOAD = BitmapFactory.decodeResource(getResources(),R.drawable.mushroom);
Canvas cb = new Canvas(Achtergrond); 
for (int m = 0;m < 50;m++)
{
cb.drawBitmap(TOAD, r.nextInt(SchermX), r.nextInt(SchermY), mPaint);
}

On the emulator the toadstools are added and runs correctly, but on my galaxy it crashed

Is there something im doing wrong?

Mars
  • 107
  • 1
  • 13
  • I forgot to mention that SchermX = random screenwidth and SchermY is random screen height – Mars Aug 27 '11 at 17:22
  • 1
    Root is not required for log access. Enable USB Debugging in Settings and then run `adb logcat` with your device connected to your computer and any drivers configured. – adamp Aug 27 '11 at 17:28
  • Thanks a lot, I now know that the error is, time to find to look for a solution. The error is: E/AndroidRuntime(24031): java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor – Mars Aug 27 '11 at 17:51
  • I'm guessing that `Achtergrond` is your background bitmap that you loaded from a resource? Try drawing both this background and your smaller images into your surface instead of drawing the smaller images into the background bitmap. – adamp Aug 27 '11 at 18:03
  • Hey Adamp, I manage to fix it to copy the bitmap that is loaded from a resource to a new bitmap, after that I can draw on the bitmap and draw it as background. I needed to use this mechanism because I need to create a bitmap background with a few images on it that contain transparency. The bitmap is only generated on start or wakeup. I found out that the app will have a lot slowdown when images with transparency are drawn on the surfaceview directly, so now all it working ok. – Mars Sep 01 '11 at 17:35

0 Answers0