Calculate button closes application

Asked

Viewed 43 times

0

I can’t understand why the Calc button makes the application close instead of calculating and showing the result in the textview.

package com.example.cc;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

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

        final EditText qfdsf = (EditText) findViewById(R.id.editText6);
        final EditText qh2e = (EditText) findViewById(R.id.editText5);
        final EditText vh = (EditText) findViewById(R.id.editText4);
        final EditText qh = (EditText) findViewById(R.id.editText3);
        final EditText qh1e = (EditText) findViewById(R.id.editText2);
        final EditText qd = (EditText) findViewById(R.id.editText);
        final TextView rs = (TextView) findViewById(R.id.textView5);

        Button clean = (Button) findViewById(R.id.button2);

        Button calc = (Button) findViewById(R.id.button);

        clean.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                qfdsf.getText().clear();
                qh2e.getText().clear();
                vh.getText().clear();
                qh.getText().clear();
                qh1e.getText().clear();
                qd.getText().clear();
                rs.setText("Resultado aparece aqui");
            }

        });

        calc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double vhvalue = Double.parseDouble(vh.getText().toString());
                int qhvalue = Integer.parseInt(qh.getText().toString());
                int qdvalue = Integer.parseInt(qd.getText().toString());
                double resulta = vhvalue * qhvalue;
                double resultb = resulta * qdvalue;
                rs.setText( String.valueOf(resultb) );


            }

        });
    }

}
  • is probably giving some Exception, what appears in Logcat?

  • @rnd_rss see here https://pastebin.com/huhyRZkQ

No answers

Browser other questions tagged

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