0

在我的项目中,我注意到模拟器中出现内存不足错误,如下所示

    08-03 01:38:28.995: W/dalvikvm(1040): threadid=1: thread exiting with uncaught exception (group=0x40015560)
    08-03 01:38:29.045: E/AndroidRuntime(1040): FATAL EXCEPTION: main
    08-03 01:38:29.045: E/AndroidRuntime(1040): java.lang.RuntimeException: Unable to  start activity ComponentInfo{sdei.edustatus/sdei.edustatus.gradebook.GradeBookActivity}:  android.view.InflateException: Binary XML file line #78: Error inflating class <unknown>
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.os.Looper.loop(Looper.java:123)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.main(ActivityThread.java:3683)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at java.lang.reflect.Method.invoke(Method.java:507)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at dalvik.system.NativeStart.main(Native Method)
    08-03 01:38:29.045: E/AndroidRuntime(1040): Caused by: android.view.InflateException: Binary XML file line #78: Error inflating class <unknown>
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.Activity.setContentView(Activity.java:1657)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at sdei.edustatus.gradebook.GradeBookActivity.onCreate(GradeBookActivity.java:311)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     ... 11 more
    08-03 01:38:29.045: E/AndroidRuntime(1040): Caused by: java.lang.reflect.InvocationTargetException
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at java.lang.reflect.Constructor.constructNative(Native Method)
    03 01:38:29.045: E/AndroidRuntime(1040):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     ... 22 more
    08-03 01:38:29.045: E/AndroidRuntime(1040): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
   08-03 01:38:29.045: E/AndroidRuntime(1040):  at   android.content.res.TypedArray.getDrawable(TypedArray.java:601)
   08-03 01:38:29.045: E/AndroidRuntime(1040):  at android.view.View.<init>(View.java:1951)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.View.<init>(View.java:1899)
    08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.view.ViewGroup.<init>(ViewGroup.java:286)
        08-03 01:38:29.045: E/AndroidRuntime(1040):     at android.widget.RelativeLayout.<init>            (RelativeLayout.java:173)
     08-03 01:38:29.045: E/AndroidRuntime(1040):    ... 25 more

我不认为应该有任何内存泄漏。是的,我正在使用一些图像,我需要单独处理它们吗?????????我的应用程序大小为 2.4mb。

我应该怎么办?

4

3 回答 3

3

在java中,我认为不应该因为gc而有任何内存泄漏

是错误的说法。如果代码引入了内存泄漏,jvm 什么也做不了。

在你的情况下,错误是

引起:java.lang.OutOfMemoryError:位图大小超出VM预算

看来您正在尝试加载大尺寸的位图图像(dalvik 不支持)。有很多关于这个问题的讨论,herehere

于 2012-08-03T15:09:33.843 回答
0

有几件事:

1)确保你没有内存泄漏,对于这个配置文件你的代码,例如,使用 MAT(http://www.eclipse.org/mat/)

2) 对图像进行适当的内存管理;使用 SoftReferences 和 WeakReferences

3) 您可以在网络上找到许多图像缓存和图像加载器(带缓存)的实现(谷歌搜索)——搜索并选择您最喜欢的一个。

但总是做上面的#1。

于 2012-08-03T15:16:47.843 回答
0

我认为您正在使用eclipse模拟器?

如果是这种情况,它可能没有足够的内存/磁盘设置来显示此行突出显示的图像:

引起:java.lang.OutOfMemoryError:位图大小超出VM预算

通过转到 AVD 检查您在 Eclipse 下的设置(如果您再次使用它),选择您的虚拟设备并点击编辑。您将在硬件下看到 SD 卡大小和内存设置。我认为您可以分配模拟器的内存大小是有限制的,因此最好使用手机。

您是否尝试过在实际设备上进行调试,通常会更好!

编辑:

其实你也可能有这个问题:

java.lang.OutOfMemoryError:位图大小超出 VM 预算 - Android

于 2012-08-03T15:12:50.877 回答