【问题标题】:My app keeps saying "unfortunately it has stopped". I don't know why it is crashing [duplicate]我的应用程序一直说“不幸的是它已经停止了”。我不知道它为什么会崩溃[重复]
【发布时间】:2016-10-27 10:06:27
【问题描述】:

在我的activity中,用户可以在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)

【问题讨论】:

  • 请向我们展示您的代码..
  • 我认为崩溃日志是不言自明的:你有一个NumberFormatException。它不喜欢 $. 这样的特殊字符,因为它需要 int
  • CapitolhillActivity.java 中的第 165 行是什么?
  • 正如@CzarMatt 所说,您的问题是不言自明的。您正在尝试解析一个数字,但您输入的是特殊字符而不仅仅是数字。如果您只输入 19.00,我相当有信心您的代码会运行良好。
  • 你试过阅读错误信息吗?

标签: java android android-studio


【解决方案1】:

您收到此异常是因为您尝试将字符串解析为整数,但字符串有美元符号。 Tri to u0get 摆脱那个标志 str.substr(1, , str.size())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-16
    • 1970-01-01
    • 2015-06-16
    • 2016-04-01
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    相关资源
    最近更新 更多