Search code examples
javaandroidnumberformatexception

how to deal with "app has stopped"problem in android studio


My app is kind of a calculator, when I hit the calculate button, the app stops and shows "app has stopped open again" . I'm calling the calculation code from eclipse work-space.

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.ctc, PID: 22378 java.lang.NumberFormatException: For input string: "any"

at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:539) at com.example.ctc.Walls1$2.onClick(Walls1.java:103) at android.view.View.performClick(View.java:6294) at android.view.View$PerformClick.run(View.java:24770) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Application terminated.`


Solution

  • Probably you are using an EditText to get the input and although you expect numbers, the retrieved data is in the form of String. In fact, you have to use editTextName.getText().toString() to further process it. If you are sure that the incoming input will be numbers, you may convert them (as, I think, you already try to) to numbers to make numerical calculations. You may try showing a numerical-only keyboard to the users so that they avoid posting other types of chars, but then, the processing differs a little.

    Without posting your actual source code, not much can be said.

    App stopped working

    is not a specific error and it may be caused by any run-time problem in your code. Thus, asking for "fix" is not the way to ask for help.

    Hope above info helps.