在我的项目中,我注意到我的模拟器中存在内存错误,如下所示
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。
我该怎么办?
答案 0 :(得分:3)
在java中,我认为由于gc
,应该有任何内存泄漏
是错误的陈述。如果代码引入了内存泄漏,jvm就无法做任何事情。
在您的情况下,错误是
引起:java.lang.OutOfMemoryError:位图大小超过VM预算
答案 1 :(得分:0)
我认为你使用的是eclipse模拟器?
如果是这种情况,它可能没有足够的内存/磁盘设置来显示此行突出显示的图像:
引起:java.lang.OutOfMemoryError:位图大小超过VM预算
通过转到AVD,在eclipse下检查您的设置(再次使用它),选择您的虚拟设备并点击编辑。您将在硬件下看到SD卡大小和内存设置。我认为你可以分配模拟器的内存大小有限,所以最好使用手机。
您是否尝试过在实际设备上进行调试,通常效果更好!
修改强>
事实上你也可能遇到这个问题:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android
答案 2 :(得分:0)
有几件事:
1)确保没有内存泄漏,对于此配置文件,您的代码,例如,使用MAT(http://www.eclipse.org/mat/)
2)对图像进行适当的内存管理;使用SoftReferences和WeakReferences
3)您可以在网络上找到许多实现(google it),用于图像缓存和图像下载(带缓存) - 搜索并选择您最喜欢的实现。
但总是在上面做#1。