-7

In my activity, the user can input numbers into a EditViews, then click a button to calculate, the result is displayed below. However, if a user edits an EditView, clicks calculate, then goes back to edit an EditView again, the app crashes when the user clicks calculate to recalculate a new total.

Full log:

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)
Juan Cruz Soler
  • 8,172
  • 5
  • 41
  • 44
Casey
  • 21
  • 1
  • 6
  • Please show us your code.. – Lal Jun 24 '16 at 17:46
  • 6
    I think the crash log is fairly self-explanatory: you have a `NumberFormatException`. It doesn't like special characters like `$` or `.` when it is expecting an `int`. – CzarMatt Jun 24 '16 at 17:47
  • what is line number 165 in `CapitolhillActivity.java`? – Lal Jun 24 '16 at 17:52
  • As @CzarMatt said your issue is rather self explanatory. You are trying to parse a number but you are inputting special characters and not just numbers. If you put 19.00 only I am rather confident your code will run fine. – basic Jun 24 '16 at 17:53
  • Have you tried reading the error message? – m_callens Jun 24 '16 at 17:54
  • You should read the stack trace before asking! $19.00 is not an int. – Tristan Richard Jun 24 '16 at 18:30
  • @Lal line 165 is Integer valuesubtotal = Integer.parseInt(subtotal.getText().toString()); – Casey Jun 26 '16 at 23:12
  • i have an edittext that the user imputs – Casey Jun 26 '16 at 23:13
  • EditText sand1; finds it in xml---- sand1= (EditText)findViewById(R.id.sand1); get entered texts from the edittexts,and convert to integers. Integer value1 = Integer.parseInt(sand1.getText().toString()); then this-- Double calculatedValue1 = (9.5*value1); then set the value to the textview, to display on screen. result1.setText("$"+ String.format( "%.2f", calculatedValue1 )); this is the entire app, i cant find my problem. i am so bad at this so i know there is a problem staring me in the face but i cant find it @Lal – Casey Jun 26 '16 at 23:16

1 Answers1

1

You are getting this exception because you trying to parse string into integer, but string has dollar sign. Tri to u0get rid of that sign str.substr (1, , str.size ())

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11