我终于准备好发布我的游戏版本,但是当我尝试在我的HTC Hero上运行它时,它会在一定程度后关闭并且logcat开始显示而不是消失。在模拟器上它完全没有问题,但在电话上,如果我使用菜单按钮重新启动游戏它强制关闭或如果我尝试从其他活动开始一个新游戏它强制关闭,并提到在上面它强制在5到7级之后关闭。
从活动变为游戏时:
07-11 20:40:27.314: ERROR/AndroidRuntime(15898): Uncaught handler: thread main exiting due to uncaught exception
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.hitmanassault/com.android.hitmanassault.Hitman}: android.view.InflateException: Binary XML file line #7: Error inflating class com.android.hitmanassault.HitmanView
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.os.Handler.dispatchMessage(Handler.java:99)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.os.Looper.loop(Looper.java:123)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at dalvik.system.NativeStart.main(Native Method)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.android.hitmanassault.HitmanView
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.Activity.setContentView(Activity.java:1629)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.hitmanassault.Hitman.onCreate(Hitman.java:49)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): ... 11 more
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): Caused by: java.lang.reflect.InvocationTargetException
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.hitmanassault.HitmanView.<init>(HitmanView.java:51)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at java.lang.reflect.Constructor.constructNative(Native Method)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): ... 21 more
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:363)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:389)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.hitmanassault.HitmanView$HitmanThread.<init>(HitmanView.java:180)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): at com.android.hitmanassault.HitmanView.ViewInit(HitmanView.java:65)
07-11 20:40:27.344: ERROR/AndroidRuntime(15898): ... 25 more
在5 - 7级之后:
07-11 20:39:35.054: ERROR/AndroidRuntime(15629): Uncaught handler: thread main exiting due to uncaught exception
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:464)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:340)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:363)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:389)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at com.android.hitmanassault.HitmanView.createSprite(HitmanView.java:74)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at com.android.hitmanassault.HitmanView.access$3(HitmanView.java:73)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at com.android.hitmanassault.HitmanView$HitmanThread.initLevel(HitmanView.java:191)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at com.android.hitmanassault.HitmanView$HitmanThread$1.run(HitmanView.java:284)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.os.Handler.handleCallback(Handler.java:609)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.os.Handler.dispatchMessage(Handler.java:92)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.os.Looper.loop(Looper.java:123)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at android.app.ActivityThread.main(ActivityThread.java:4595)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at java.lang.reflect.Method.invoke(Method.java:521)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-11 20:39:35.134: ERROR/AndroidRuntime(15629): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
好像你的内存不足了。我建议你查看下面的链接,了解避免内存泄漏的方法。
http://developer.android.com/resources/articles/avoiding-memory-leaks.html
使用位图时要注意的一点是,如果您不再使用位图内存,则应使用Bitmap.recycle()
方法清理位图内存。
要检查的另一件事是确保您的资产已被压缩。我注意到在使用XML布局并加载大量未压缩资源时,可能会导致内存泄漏。
如果您使用ImageView
并因任何原因保留它们,请务必WeakReference
ImageView
而不是ImageView
本身,以便您知道如果已清理ImageView。