在我的活动中,用户可以在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 :(得分:0)
您收到此异常是因为您尝试将字符串解析为整数,但字符串具有美元符号。 Tri to u0get摆脱那个标志 str.substr(1,str.size())