Android程序报OutOfMemory错误,具体Log如下,各位大虾们帮忙看下怎么解决,小弟拜谢了!

飘奇 发布于 2012/09/03 14:17
阅读 6K+
收藏 0

小弟最近在做一个项目遇到一个十分棘手的问题:就是我们做的这个程序需要用的图片的确不少,还用了Animation动画、PopupWindow等。我简单的说一下就是主界面一个Activity上有选项,当点击开始动画并在动画结束后弹出PopupWindow窗口进入二级选项界面,就这样反复地打开关闭五六次的时候就会报OutOfMemory错误,Log如下:

 

09-03 14:09:07.370: D/AndroidRuntime(9454): Shutting down VM
09-03 14:09:07.370: W/dalvikvm(9454): threadid=1: thread exiting with uncaught exception (group=0x40a4a1f8)
09-03 14:09:07.370: E/AndroidRuntime(9454): FATAL EXCEPTION: main
09-03 14:09:07.370: E/AndroidRuntime(9454): android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.createView(LayoutInflater.java:606)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.View.inflate(View.java:13560)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.allrun.cfsn.ui.lifebusiness.HealthyFoodCategoryView.showHealthyFoodCategory(HealthyFoodCategoryView.java:75)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.allrun.cfsn.ui.lifebusiness.HealthyFoodCategoryView.showWindow(HealthyFoodCategoryView.java:388)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.allrun.cfsn.ui.MainAct.showCategoryWindow(MainAct.java:338)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.allrun.cfsn.ui.MainAct$1.handleMessage(MainAct.java:287)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.os.Looper.loop(Looper.java:137)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at java.lang.reflect.Method.invokeNative(Native Method)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at java.lang.reflect.Method.invoke(Method.java:511)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at dalvik.system.NativeStart.main(Native Method)
09-03 14:09:07.370: E/AndroidRuntime(9454): Caused by: java.lang.reflect.InvocationTargetException
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at java.lang.reflect.Constructor.constructNative(Native Method)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.LayoutInflater.createView(LayoutInflater.java:586)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	... 20 more
09-03 14:09:07.370: E/AndroidRuntime(9454): Caused by: java.lang.OutOfMemoryError
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.content.res.Resources.loadDrawable(Resources.java:1937)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.View.<init>(View.java:2785)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.view.ViewGroup.<init>(ViewGroup.java:385)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.widget.LinearLayout.<init>(LinearLayout.java:174)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	at android.widget.LinearLayout.<init>(LinearLayout.java:170)
09-03 14:09:07.370: E/AndroidRuntime(9454): 	... 23 more

希望大虾们能帮小弟看一看,小弟万分感谢!

2012.09.03下午

大连奥远集团

王超

加载中
0
华兹格
华兹格
是不是你一直加载图片,导致的。图片不用的要释放掉,用的才显示。
飘奇
飘奇
也不是一直在加载,就是每一个选项得进入PopupWindow二级窗口这时得加载图片,并且我用Bipmap加载的在点击二级选项动画结束的时候我调recycle()放了还gc了下,回收了也,各种百度Google的,就是无果,哎!
0
林彩神
林彩神
如果图片一直被引用着是回收不了的
飘奇
飘奇
回复 @Onions : 试了下 不起到主体作用好像 还是要谢谢你呦
林彩神
林彩神
bitmap回收后置为null试试看,调用gc系统也不是立即回收的。个人愚见。
飘奇
飘奇
图片一直被引用着?我没理解啥意思 大虾。这样的,我的图片只是选项的背景,就是图文图片ImageView,一直被引用。。。小弟愚拙,望解释一下,多谢!
0
黄杨奇
黄杨奇
用ddms工具,进行内存分析,可以找到占用内存的对象,然后再去着相应代码,修复它
飘奇
飘奇
研究一下午了 上网也搜了那个MAT工具,应该说我没整明白怎么用吧,照着文档弄的但是没有对上号,呜呜呜 同样谢谢你哈
0
ydww
ydww

在Activity的ondestroy方法中,recycle该图片

 @Override
 protected void onDestroy() {
  // TODO Auto-generated method stub
  if(bitmap!=null&&!bitmap.isRecycled()){
   bitmap.recycle();
   bitmap=null;
  }
  super.onDestroy();
 }

 

返回顶部
顶部