我的應用程序總是隨機時間間隔(大多數從幾分鐘到20分鐘左右)關機。出現「應用程序停止工作」消息框。最大的問題是,我沒有在應用程序中做任何事情(比如與它進行交互),而且它本身就是隨機關機。下面是logcat的打印:突然的應用程序關閉沒有做任何活動,拋出IllegalStateException onMeasure()
07-15 20:34:16.595 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 141
9K, 44% free 13902K/24391K, paused 4ms+9ms, total 66ms
07-15 20:34:28.997 27361-27363/test.game D/dalvikvm: GC_CONCURRENT freed 1416K, 43% free 13903K/24391K, paused 3ms+7ms, total 56ms
07-15 20:34:29.418 27361-27361/test.game D/AndroidRuntime: Shutting down VM
07-15 20:34:29.418 27361-27361/test.game W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x412b52a0)
07-15 20:34:29.498 27361-27361/test.game E/AndroidRuntime: FATAL EXCEPTION: main java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
at android.view.View.measure(View.java:15293)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
at android.view.View.measure(View.java:15288)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2397)
at android.view.View.measure(View.java:15288)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1113)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4481)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
有人會說,那是因爲我重寫方法onMeasure()
時沒有寫setMeasuredDimension()
。另外,文檔說你必須將這行寫入onMeasure,否則將引發IllegalStateException(see it here)。
但是我並沒有在我的整個項目中的任何地方壓倒onMeasure
,所以問題不在這裏(至少在這種情況下不在我身邊)。
幾點需要注意:
- 這個充滿logcat的日誌,任何這些行(「在機器人 ...」)的未鏈接到我的代碼,一切順利來源 - 這意味着所有這些鏈接灰色
- 這種異常總是隻發生在我的S3迷你(Android 4.1.2),但從來沒有發生在我舊的Galaxy Ace S5830i(android 2.3.6)(和是,我測試了很多 - 超過20小時的舊手機和應用程序仍在運行!)。
- 在模擬器從來沒有發生過
- 有在後臺運行的操作,這可能導致此異常
我想發佈一些代碼沒有「縮放視圖」,但我絕對不知道在哪裏這個異常可能會被拋出。
如果有人能幫忙,我會非常感激。我迷失在這一點......
因此,你認爲它可能會導致一些,在一段時間後,不存在的觀點?我有幾個被引用爲靜態視圖。順便說一下,我的應用程序中有一個viewPager,我也將其稱爲靜態viewPager。 我會看看它。 – BlackJack
似乎是最可能的原因。所有最好的兄弟!這樣的錯誤是最難找到和糾正的。 –
謝謝,但使viewPager非靜態沒有幫助:(我會盡量減少我的應用程序中更多的靜態視圖,但這是最大的希望:/ – BlackJack