5 Replies - 1863 Views - Last Post: 17 February 2013 - 12:04 PM

#1 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Posted 11 February 2013 - 07:28 PM

Hi, so I'm fairly new to Android development, and I've been transferring one of my Windows Phone games to Android. However, I ran into the error in the title: "java.lang.OutOfMemoryError: bitmap size exceeds VM budget". Here's the code real quick:

	//Declares all of the Bitmaps that will be used
	private void DeclareBitmaps()
	{
		CircleBP[0] = BitmapFactory.decodeResource(getResources(), R.drawable.circle);
		CircleBP[1] = BitmapFactory.decodeResource(getResources(), R.drawable.circle2);
		CircleBP[2] = BitmapFactory.decodeResource(getResources(), R.drawable.circle3);
		CircleBP[3] = BitmapFactory.decodeResource(getResources(), R.drawable.circle4);
		CircleBP[4] = BitmapFactory.decodeResource(getResources(), R.drawable.circle5);
		CircleBP[5] = BitmapFactory.decodeResource(getResources(), R.drawable.circle6);
		CircleBP[6] = BitmapFactory.decodeResource(getResources(), R.drawable.circle7);
		GameTypeButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.gametype_button);
		IntenseButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.intense_button);
		MainMenuButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.mainmenu_button);
		NormalButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.normal_button);
		PauseButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.pause_button);
		PlayAgainButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.playagain_button);
		ResumeButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.resume_button);
		ReturnMenuButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.returnmenu_button);
		SeperationLineBP = BitmapFactory.decodeResource(getResources(), R.drawable.seperation_line);
		StartGameButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.startgame_button);
		TypeReturnMenuButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.typereturnmenu_button);
		GreenNormalButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.green_normal_button);
		GreenIntenseButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.green_intense_button);
		GeneralButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.general_button);
		OptionsButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.options_button);
		CheckBoxBP = BitmapFactory.decodeResource(getResources(), R.drawable.check_box);
		CheckBP = BitmapFactory.decodeResource(getResources(), R.drawable.check);
	}



So basically what I do in this method is just assign all my sprites. The part where I have an issue is in the line
		OptionsButtonBP = BitmapFactory.decodeResource(getResources(), R.drawable.options_button);



I've tried increasing the VM heapsize for the emulator I'm using but it still doesn't work. I've tried a little debugging by taking out the line where I declare this, and the issue goes away, of course then I have issues with wherever else I use this, but does anyone know why this happens? I don't think it's actually because the size is going over because I have two other sprites afterwards. Is there any other reason this might happen?

Is This A Good Question/Topic? 0
  • +

Replies To: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

#2 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,097
  • Joined: 13-March 09

Re: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Posted 14 February 2013 - 04:47 AM

That error is often a sign that the bitmap is to big for the Video memory to handle.
The way a company handles this, is that they use small 9-patch images as much as possible.
If they can, then they only use a bitmap for the player. But often, even then player is not a pure bitmap.

I'm not saying that this is the case with your game, but i could be.
What are the size of the bitmap that gives error?
Was This Post Helpful? 0
  • +
  • -

#3 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Posted 16 February 2013 - 07:10 PM

It was a pretty big bitmap, but I figured out a way to get rid of the error through a combination of making my images smaller, finding ways to streamline my the sizing of my bitmaps by getting rid of a couple temp bitmaps when using the Bitmap.createScaledBitmap method. But thanks!
Was This Post Helpful? 0
  • +
  • -

#4 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,097
  • Joined: 13-March 09

Re: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Posted 17 February 2013 - 04:41 AM

Couldn't you jut scale it down by hand, and then re-add it to the game?
That way you'll save time and resources on the device/emulator when you run it.
Was This Post Helpful? 0
  • +
  • -

#5 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Posted 17 February 2013 - 12:01 PM

It's more when I'm trying to make something take up like half the screen and since there are many different sized screens for Androids, I need to scale the Bitmap to screen size.
Was This Post Helpful? 0
  • +
  • -

#6 EndLessMind  Icon User is offline

  • These are the droids you're looking for
  • member icon

Reputation: 193
  • View blog
  • Posts: 1,097
  • Joined: 13-March 09

Re: java.lang.OutOfMemoryError: bitmap size exceeds VM budget

Posted 17 February 2013 - 12:04 PM

Is it not possible for you to use a 9-patch image?
That way you only need a small image with low resolution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1