How to fix a 鈥渏ava.lang.OutOf MemoryError: bitmap size exceeds VM budget 鈥?error on andr oid

by Sheepz » Tue, 31 Aug 2010 04:37:17 GMT


Sponsored Links
 i all, I've seen this question asked many times but none of the
answers really made sense in what I'm doing... I have an android game
(see source at Google source control:
http://code.google.com/p/bestcardgameever-android/source/browse/#svn/trunk/bestcardgameever-android/Branches/Yaniv%20For%20Android)
It's a card game, and I've used a method that redraws each hand every
round - that might be wasteful but I couldn't think of a better way to
do it. Here is the code for the redrawHand method:

private void redrawHand(Hand hand) {
ImageView[] cardView = hand.getCardsViews();
View container = hand.getContainer();
for (int i = 0; i < GameData.YANIV_NUM_CARDS; i++) {
PlayingCard card = hand.getCardByLocation(i);
if (card != null) {
// Show Card
cardView[i].setVisibility(View.VISIBLE);
int resId;
if (hand.shouldCardsBeShown()) {
resId = card.getImageResourceId();
} else {
resId = R.drawable.back;
}
cardView[i].setImageResource(resId);
if (hand.isHumanPlayer()) {
// when selected, move up 15 pixels
boolean isSelected = hand.isCardSelected(i);
((LinearLayout.LayoutParams)
cardView[i].getLayoutParams()).bottomMargin = isSelected? 15 : 0;
} } else {
cardView[i].setVisibility(View.INVISIBLE); } } // Set player name
hand.getHandLabelView().setText(hand.getHandLabel());
container.requestLayout(); }

After installing ACRA (http://code.google.com/p/acra/wiki/ACRAHowTo) I
have started getting crash reports from devices saying the following:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget at
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:363) at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:212) at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:
673) at android.content.res.Resources.loadDrawable(Resources.java:
1639) at android.content.res.Resources.getDrawable(Resources.java:535)
at android.widget.ImageView.resolveUri(ImageView.java:541) at
android.widget.ImageView.setImageResource(ImageView.java:293) at
com.geekadoo.ui.Yaniv.redrawHand(Yaniv.java:765) at
com.geekadoo.ui.Yaniv.performYaniv(Yaniv.java:539) at
com.geekadoo.ui.Yaniv.performYanivHandler(Yaniv.java:503) at
com.geekadoo.ui.Yaniv.access$1(Yaniv.java:502) at com.geekadoo.ui.Yaniv
$2.onClick(Yaniv.java:323) at android.view.View.performClick(View.java:
2196) at android.view.View.onTouchEvent(View.java:3849) at
android.widget.TextView.onTouchEvent(TextView.java:6376) at
android.view.View.dispatchTouchEvent(View.java:3385) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:872) at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1764) at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:
1213) at android.app.Activity.dispatchTouchEvent(Activity.java:2066)
at com.android.internal.policy.impl.PhoneWindo



Other Threads

1. Strange platform error in Droid(2.0.1), Hero(1.5)

Hi,
I have been running into strange problems. here is the stacktrace it seems ,
there is nowhere the error is in my application, I donot know why this
exception/error is comming..

java.lang.NullPointerException at
android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:355) at
android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) at
android.widget.AbsListView.obtainView(AbsListView.java:1274) at
android.widget.ListView.makeAndAddView(ListView.java:1668) at
android.widget.ListView.fillDown(ListView.java:637) at
android.widget.ListView.fillFromTop(ListView.java:694) at
android.widget.ListView.layoutChildren(ListView.java:1521) at
android.widget.AbsListView.onLayout(AbsListView.java:1113) at
android.view.View.layout(View.java:6831) at
android.widget.FrameLayout.onLayout(FrameLayout.java:333) at
android.view.View.layout(View.java:6831) at
android.widget.FrameLayout.onLayout(FrameLayout.java:333) at
android.view.View.layout(View.java:6831) at
android.view.ViewRoot.performTraversals(ViewRoot.java:996) at
android.view.ViewRoot.handleMessage(ViewRoot.java:1633) at
android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:123) at
android.app.ActivityThread.main(ActivityThread.java:4338) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:521) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) at
dalvik.system.NativeStart.main(Native Method)

-- 

2. Unable to get the trigger with Repeat Alarm when set in BootUp Sequence

Hi All,

I have to run a particular background task everyday, hence  I chose to  set
a Repeat Alarm  as soon as BOOT_COMPLETE event is received with 24hrs  as
interval. When tested, observed that  alarm expiry is not received to the
IntentReceiver,  when phone successfully powers up. Unable to figure out the
root cause. Please  someone help  me to resolve this issue, as it is
blocking our Application. Appreciate, your quick response.

Best Regards,
Bindu

-- 

3. try to see hprof dump from ddms

4. android and google docs

5. Waiting for Debugger on Release Version.

6. EMMA code coverage

7. how to load XML files dynamically