我有一个应用程序,在屏幕上绘制一个正方形。用户可以使用他/她的手指(触摸事件)等移动方块,增加其宽度和高度。用户还可以添加任意数量的方块并单独移动它们。
该应用程序适用于大多数部分,但有时它会崩溃,并给出以下错误
05-09 11:32:49.488: E/AndroidRuntime(24826): FATAL EXCEPTION: main
05-09 11:32:49.488: E/AndroidRuntime(24826): Process: com.example, PID: 24826
05-09 11:32:49.488: E/AndroidRuntime(24826): java.lang.OutOfMemoryError
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.graphics.Bitmap.nativeCreate(Native Method)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.graphics.Bitmap.createBitmap(Bitmap.java:835)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.graphics.Bitmap.createBitmap(Bitmap.java:779)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.example.Square.isClicked(Square.java:478)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.example.EditBubbleView$2.onTouch(EditBubbleView.java:378)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.View.dispatchTouchEvent(View.java:7731)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2238)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.app.Activity.dispatchTouchEvent(Activity.java:2466)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.View.dispatchPointerEvent(View.java:7916)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4031)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3910)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3510)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3479)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3586)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3487)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3643)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3510)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3479)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3487)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3460)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5728)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5659)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5630)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5808)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.os.MessageQueue.nativePollOnce(Native Method)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.os.MessageQueue.next(MessageQueue.java:138)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.os.Looper.loop(Looper.java:123)
05-09 11:32:49.488: E/AndroidRuntime(24826): at android.app.ActivityThread.main(ActivityThread.java:5102)
05-09 11:32:49.488: E/AndroidRuntime(24826): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 11:32:49.488: E/AndroidRuntime(24826): at java.lang.reflect.Method.invoke(Method.java:515)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
05-09 11:32:49.488: E/AndroidRuntime(24826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
05-09 11:32:49.488: E/AndroidRuntime(24826): at dalvik.system.NativeStart.main(Native Method)
任何人都可以告诉我如何解决这个问题。谢谢 :)
你可以把它写到你的manifest.xml
文件中。
android:largeHeap="true"
这是内存泄漏的情况。首先检查这两个代码
at com.example.Square.isClicked(Square.java:478)05-09 11:32:49.488: E/AndroidRuntime(24826):
at com.example.EditBubbleView$2.onTouch(EditBubbleView.java:378)
这两种方法是否被同时调用????如果可能的话,然后将代码粘贴到此处,以便我们可以查看。