Short Version:
Is there a guaranteed minimum VM Budget Size (or at least a reasonable target)? I am exceeding it with an xml layout that is nothing but a linearlayout wrapping a single 30KB image.
Long version:
I'm getting the following error related to bitmap exceeding vm budget:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dah.rh/com.dah.rh.activities.SplashActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
at android.app.ActivityThread.access$2200(ActivityThread.java:131)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4702)
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)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
at android.app.Activity.setContentView(Activity.java:1629)
at com.dah.rh.activities.SplashActivity.onCreate(SplashActivity.java:26)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
... 11 more
Caused by: java.lang.re开发者_运维百科flect.InvocationTargetException
at android.widget.ImageView.<init>(ImageView.java:105)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 22 more
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.TypedArray.getDrawable(TypedArray.java:549)
at android.widget.ImageView.<init>(ImageView.java:115)
... 26 more
The line in the stacktrace that is my code is the following:
setContentView(R.layout.splash_page);
From here, Android attempts to inflate the resource splash_page.xml listed below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"/>
</LinearLayout>
The image "logo.png" is a 240x138px png sizing in at 30KB. It seems strange to me that this would exceed the budget whereas other pages where I have loaded 6 images totaling over 35KB total have not exceeded the budget. It seems like the only thing I can do is to shrink the image, but I have no idea how small to make it.
The minimum budget, so to speak, is 16MB, insofar as the smallest maximum heap size for an Android application is 16MB. You are not exceeding it with a single PNG file of the size you describe.
精彩评论