我遇到問題。我的應用程序正常工作,但是當我在佈局XML中添加新的ImageView時,它會崩潰。是因爲在一個活動中有太多的圖像或太多的內存?圖像有511 kb和第733 X 3999添加ImageView時崩潰的應用程序
這裏是我的崩潰日誌:
10-19 14:09:04.762: E/AndroidRuntime(15605): FATAL EXCEPTION: main
10-19 14:09:04.762: E/AndroidRuntime(15605): Process: com.formulas.mpc, PID: 15605
10-19 14:09:04.762: E/AndroidRuntime(15605): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.formulas.mpc/com.formulas.mpc.ActivityPhysicsMenu}: android.view.InflateException: Binary XML file line #295: Error inflating class <unknown>
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.ActivityThread.access$800(ActivityThread.java:144)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.os.Handler.dispatchMessage(Handler.java:102)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.os.Looper.loop(Looper.java:212)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.ActivityThread.main(ActivityThread.java:5135)
10-19 14:09:04.762: E/AndroidRuntime(15605): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605): at java.lang.reflect.Method.invoke(Method.java:515)
10-19 14:09:04.762: E/AndroidRuntime(15605): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
10-19 14:09:04.762: E/AndroidRuntime(15605): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
10-19 14:09:04.762: E/AndroidRuntime(15605): at dalvik.system.NativeStart.main(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605): Caused by: android.view.InflateException: Binary XML file line #295: Error inflating class <unknown>
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
10-19 14:09:04.762: E/AndroidRuntime(15605): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-19 14:09:04.762: E/AndroidRuntime(15605): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:297)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.Activity.setContentView(Activity.java:1929)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
10-19 14:09:04.762: E/AndroidRuntime(15605): at com.formulas.mpc.ActivityPhysicsMenu.onCreate(ActivityPhysicsMenu.java:20)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.Activity.performCreate(Activity.java:5231)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
10-19 14:09:04.762: E/AndroidRuntime(15605): ... 11 more
10-19 14:09:04.762: E/AndroidRuntime(15605): Caused by: java.lang.reflect.InvocationTargetException
10-19 14:09:04.762: E/AndroidRuntime(15605): at java.lang.reflect.Constructor.constructNative(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
10-19 14:09:04.762: E/AndroidRuntime(15605): ... 28 more
10-19 14:09:04.762: E/AndroidRuntime(15605): Caused by: java.lang.OutOfMemoryError
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:856)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.content.res.Resources.loadDrawable(Resources.java:2129)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.widget.ImageView.<init>(ImageView.java:129)
10-19 14:09:04.762: E/AndroidRuntime(15605): at android.widget.ImageView.<init>(ImageView.java:119)
10-19 14:09:04.762: E/AndroidRuntime(15605): ... 31 more
它不是關於影像尺寸,請檢查您的XML代碼的 – 2014-10-19 12:20:22
可能重複[安卓:BitmapFactory.decodeStream()了內存與2MB免費堆一個400KB的文件(HTTP://計算器問題/ 11820266/android-bitmapfactory-decodestream-out-of-memory-with-a-400kb-file-with-2mb-f) – ToYonos 2014-10-19 12:26:34