2011-02-11 77 views
1

短版本:什麼是最低VM預算大小?

是否有保證最低VM預算大小(或至少是合理的目標)?我用xml佈局超越了它,它只是一個包含單個30KB圖像的線性佈局。

龍版本:

我越來越爲位圖超過VM預算有關的以下錯誤:

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.reflect.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 

在是我的代碼的堆棧跟蹤行如下:

setContentView(R.layout.splash_page); 

從這裏開始,Android會嘗試使下面列出的資源splash_page.xml膨脹:

<?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> 

圖像「logo.png」是一個240x138px的PNG大小在30KB。對我來說這似乎很奇怪,這將超出預算,而其他頁面,我已經加載了總共超過35KB的6張圖片,但沒有超出預算。看起來我唯一能做的就是縮小圖像,但我不知道它有多小。

+0

也許你的PNG文件已損壞?嘗試編輯它並保存它的新副本...(在這裏黑暗中拍攝) – Damp 2011-02-11 19:58:31

+0

「adb logcat」輸出中是否有指示失敗原因的內容?看起來不像OOM的情況。 – fadden 2011-02-12 00:54:39

回答

0

可以說,最低預算是16MB,只要Android應用程序的最小堆大小爲16MB即可。你沒有超過它所描述的大小的單個PNG文件。

相關問題