2016-06-24 38 views
-7

在我的活動中,用戶可以將數字輸入到EditViews中,然後單擊一個按鈕進行計算,結果顯示在下面。但是,如果用戶編輯EditView,單擊計算,然後再次編輯EditView,則當用戶單擊計算以重新計算新總計時,該應用會崩潰。我的應用一直在說「不幸已停止」。我不知道它爲什麼會崩潰

完整的日誌:

06-24 09:14:06.025 2618-2637/washingtondeli.groupboxlunchesestimateandordering D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true 

                           [ 06-24 09:14:06.035 2618: 2618 D/   ] 
                           HostConnection::get() New Host Connection established 0xaac28fe0, tid 2618 
06-24 09:14:06.109 2618-2637/washingtondeli.groupboxlunchesestimateandordering I/OpenGLRenderer: Initialized EGL, version 1.4 
06-24 09:14:10.220 2618-2637/washingtondeli.groupboxlunchesestimateandordering E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae6cc2a0 
06-24 09:14:10.226 2618-2637/washingtondeli.groupboxlunchesestimateandordering D/OpenGLRenderer: endAllStagingAnimators on 0xb2a8d580 (RippleDrawable) with handle 0xae452850 
06-24 09:14:13.718 2618-2618/washingtondeli.groupboxlunchesestimateandordering W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=304.2444, y[0]=1010.4492, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20361, downTime=16521, deviceId=0, source=0x1002 } 
06-24 09:14:13.718 2618-2618/washingtondeli.groupboxlunchesestimateandordering W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=304.2444, y[0]=1010.4492, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20361, downTime=16521, deviceId=0, source=0x1002 } 
06-24 09:14:13.718 2618-2618/washingtondeli.groupboxlunchesestimateandordering W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=304.2444, y[0]=1010.4492, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20361, downTime=16521, deviceId=0, source=0x1002 } 
06-24 09:14:13.718 2618-2618/washingtondeli.groupboxlunchesestimateandordering W/ViewRootImpl: Cancelling event due to no window focus: MotionEvent { action=ACTION_CANCEL, actionButton=0, id[0]=0, x[0]=304.2444, y[0]=1010.4492, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=20361, downTime=16521, deviceId=0, source=0x1002 } 
06-24 09:14:37.797 2618-2618/washingtondeli.groupboxlunchesestimateandordering D/AndroidRuntime: Shutting down VM 


                           --------- beginning of crash 
06-24 09:14:37.797 2618-2618/washingtondeli.groupboxlunchesestimateandordering E/AndroidRuntime: FATAL EXCEPTION: main 
                           Process: washingtondeli.groupboxlunchesestimateandordering, PID: 2618 
                           java.lang.NumberFormatException: Invalid int: "$19.00" 
                            at java.lang.Integer.invalidInt(Integer.java:138) 
                            at java.lang.Integer.parse(Integer.java:410) 
                            at java.lang.Integer.parseInt(Integer.java:367) 
                            at java.lang.Integer.parseInt(Integer.java:334) 
                            at washingtondeli.groupboxlunchesestimateandordering.CapitolhillActivity.calculate2(CapitolhillActivity.java:165) 
                            at washingtondeli.groupboxlunchesestimateandordering.CapitolhillActivity$2.onClick(CapitolhillActivity.java:131) 
                            at android.view.View.performClick(View.java:5198) 
                            at android.view.View$PerformClick.run(View.java:21147) 
                            at android.os.Handler.handleCallback(Handler.java:739) 
                            at android.os.Handler.dispatchMessage(Handler.java:95) 
                            at android.os.Looper.loop(Looper.java:148) 
                            at android.app.ActivityThread.main(ActivityThread.java:5417) 
                            at java.lang.reflect.Method.invoke(Native Method) 
                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
+0

請向我們展示您的代碼.. – Lal

+6

我認爲崩潰日誌相當不言自明:您有一個'NumberFormatException'。當它期待int時,它不喜歡像'$'或'.'這樣的特殊字符。 – CzarMatt

+0

'CapitolhillActivity.java'中的第165行是什麼? – Lal

回答

0

您收到此異常,因爲你試圖解析字符串轉換成整數,但字符串中有美元符號。三,以擺脫該標誌 str.substr(1,,str.size())

相關問題