相关疑难解决方法(0)

Android outofmemory错误位图大小超过2.3.3中的vm预算

我知道这问题很少见.他们都没有清楚解决方案.让我解释一下这个问题.

  1. 我有一个Activity,一次加载4个图像.
  2. 我在onResume()方法中加载图像.
  3. 加载时,Activity会引发位图错误.

笔记.

  1. 我使用setImageResource(R.drawable.xxxx)方法调用设置图像,而不是直接使用bitmap/drawables.
  2. 图像正确缩放.
  3. 活动在2.3之前的所有模拟器中都运行良好,并且在实际设备(三星Galaxy 5)中工作精细
  4. 错误出现在首次初始化时,并且不会触发方向更改事件.
  5. 图像尺寸为800 x 600,平均尺寸为15kb(每个).

让我知道任何解决方案.如果你有与Android 2.3.3模拟器类似的问题,也请告诉我.

[更新] -snippets

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            ...
    img_topLeft = (ImageView) findViewById(R.id.Img_Alph_Q_TopLeft);
    img_topRight = (ImageView) findViewById(R.id.Img_Alph_Q_TopRight);
    img_bottomLeft = (ImageView) findViewById(R.id.Img_Alph_Q_BottomLeft);
    img_bottomRight = (ImageView) findViewById(R.id.Img_Alph_Q_BottomRight);
   ...
   }
protected void onResume() {
    super.onResume();
            img_topLeft.setImageResource(R.drawable.xxx);
            img_topRight.setImageResource(R.drawable.xxx);
            img_bottomLeft.setImageResource(R.drawable.xxx);
            img_bottomRight.setImageResource(R.drawable.xxx);
   ...
   }
Run Code Online (Sandbox Code Playgroud)

03-21 08:59:17.362:ERROR/dalvikvm-heap(5883):4320000字节的外部分配对于此过程来说太大了.03-21 08:59:17.412:ERROR/GraphicsJNI(5883):VM不允许我们分配4320000字节03-21 08:59:17.432:ERROR/AndroidRuntime(5883):致命异常:主03-21 08: 59:17.432:ERROR/AndroidRuntime(5883):java.lang.OutOfMemoryError:位图大小超过VM预算03-21 08:59:17.432:ERROR/AndroidRuntime(5883):at android.graphics.Bitmap.nativeCreate(Native Method) 03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.graphics.Bitmap.createBitmap(Bitmap.java:477)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android. graphics.Bitmap.createBitmap(Bitmap.java:444)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)03-21 08:59: 17.432:ERROR/AndroidRuntime(5883):在android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.graphics.BitmapFactory.decodeStream(BitmapFactory) .java:473)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.graphics.BitmapFact ory.decodeResourceStream(BitmapFactory.java:336)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)03-21 08:59: 17.432:ERROR/AndroidRuntime(5883):在android.content.res.Resources.loadDrawable(Resources.java:1709)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.content.res.Resources .getDrawable(Resources.java:581)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.widget.ImageView.resolveUri(ImageView.java:501)03-21 08:59:17.432:ERROR/AndroidRuntime(5883):在android.widget.ImageView.setImageResource(ImageView.java:280)03-21 …

android android-emulator android-layout

11
推荐指数
1
解决办法
7430
查看次数

标签 统计

android ×1

android-emulator ×1

android-layout ×1