在我的Android应用程序中的内存问题

时间:2013-07-12 10:05:58

标签: android memory

    07-12 12:01:47.016: E/AndroidRuntime(24203): FATAL EXCEPTION: main
07-12 12:01:47.016: E/AndroidRuntime(24203): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.oman.muscat/com.oman.muscat.settings.Settings}: android.view.InflateException: Binary XML file line #55: Error inflating class <unknown>
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.os.Looper.loop(Looper.java:137)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.ActivityThread.main(ActivityThread.java:4898)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at java.lang.reflect.Method.invokeNative(Native Method)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at java.lang.reflect.Method.invoke(Method.java:511)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at dalvik.system.NativeStart.main(Native Method)
07-12 12:01:47.016: E/AndroidRuntime(24203): Caused by: android.view.InflateException: Binary XML file line #55: Error inflating class <unknown>
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at com.muscat.menudrawer.MenuDrawer.setContentView(MenuDrawer.java:1055)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at com.oman.muscat.settings.Settings.onCreate(Settings.java:92)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.Activity.performCreate(Activity.java:5206)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
07-12 12:01:47.016: E/AndroidRuntime(24203):    ... 11 more
07-12 12:01:47.016: E/AndroidRuntime(24203): Caused by: java.lang.reflect.InvocationTargetException
07-12 12:01:47.016: E/AndroidRuntime(24203):    at java.lang.reflect.Constructor.constructNative(Native Method)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
07-12 12:01:47.016: E/AndroidRuntime(24203):    ... 23 more
07-12 12:01:47.016: E/AndroidRuntime(24203): Caused by: java.lang.OutOfMemoryError
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:623)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:476)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.content.res.Resources.loadDrawable(Resources.java:1963)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.View.<init>(View.java:3436)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.ViewGroup.<init>(ViewGroup.java:432)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.widget.LinearLayout.<init>(LinearLayout.java:176)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.widget.LinearLayout.<init>(LinearLayout.java:172)
07-12 12:01:47.016: E/AndroidRuntime(24203):    ... 26 more

请提供一些解决方案以解决此问题。

2 个答案:

答案 0 :(得分:0)

您似乎在活动中加载大位图,并且设备内存不足。以下是在Android中正确显示位图的指南 - http://developer.android.com/training/displaying-bitmaps/index.html

答案 1 :(得分:0)

从日志中可以看出,FATAL异常是由java.lang.OutOfMemoryError引起的。 这意味着在创建期间创建的位图未正确解除分配。

07-12 12:01:47.016: E/AndroidRuntime(24203): Caused by: android.view.InflateException: Binary XML file line #55: Error inflating class <unknown>
07-12 12:01:47.016: E/AndroidRuntime(24203):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
07-12 12:01:47.016: E/AndroidRuntime(24203):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)

您是否检查了是否要取消分配位图,同时暂停或销毁活动或不。(在onDestroy()或onPause()中。