Error pressing button in app created from Android Studio

Asked

Viewed 23 times

1

Guys, here’s what happens when I test this code on the emulator it works normally, but when I install the apk on some physical cell phone and press the button btn the application hangs and says it stopped working and closes.

OBS1: this only happens when I use the Double.parseDouble, if I set a fixed value it works normally.

OBS2: already tested on 2 phones, one with the version of android 4.4.2 and the other 4.1.2, and the minimum version for the program is 2.3.3.

Edit: I opened the application with the mobile phone in USB and appeared the following error while pressing the button:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.lucas.calculadora, PID: 28842
              java.lang.NumberFormatException: Invalid double: ""
                  at java.lang.StringToReal.invalidReal(StringToReal.java:63)
                  at java.lang.StringToReal.parseDouble(StringToReal.java:248)
                  at java.lang.Double.parseDouble(Double.java:295)
                  at com.example.lucas.calculadora.MainActivity$1.onClick(MainActivity.java:34)
                  at android.view.View.performClick(View.java:4633)
                  at android.view.View$PerformClick.run(View.java:19274)
                  at android.os.Handler.handleCallback(Handler.java:733)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:146)
                  at android.app.ActivityThread.main(ActivityThread.java:5593)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                  at dalvik.system.NativeStart.main(Native Method)

The code:

public class MainActivity extends AppCompatActivity {

    private EditText edtValorA;
    private EditText edtValorB;
    private EditText edtValorC;
    private Button btn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout);


        edtValorA = (EditText) findViewById(R.id.edtValorA);
        edtValorB = (EditText) findViewById(R.id.edtValorB);
        edtValorC = (EditText) findViewById(R.id.edtValorC);
        btn = (Button) findViewById(R.id.btn);



        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {

                double valorA = Double.parseDouble(edtValorA.getText().toString());

                double valorB = Double.parseDouble(edtValorB.getText().toString());
                double valorC = Double.parseDouble(edtValorC.getText().toString());

                double res = valorB + valorA + valorC;

                AlertDialog.Builder dialogo = new AlertDialog.Builder(MainActivity.this);

                dialogo.setTitle("Resultado");

                dialogo.setMessage("Soma: " );

                dialogo.setNeutralButton("OK", null);

                dialogo.show();
            }
        });

    }
}
  • Which error appears in android RUN?

  • 1

    Use Android Studio and debug via usb with the phone and post the logcat with the errors, if you do not know, take a look at google, will have all step by step. Just edit your question and add this.

  • 1

    @Florida if Voce runs the app on the phone with it connected by USB cable the error appears in RUN, I assume that the app is not in the APP store so this is the expected way for it to test on a mobile. And he’s already doing it, so your comment makes no sense.

  • I believe a double this empty Some of these edittext ta no numeric value

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.