Android app closes when performing calculation

Asked

Viewed 77 times

1

I’m making an app that has a very specific medical calculator. In AVD, the calculation appears divinely well. On real devices, gives error and the application is closed.

Somebody help me out there?

Calcactivity:

package unicatolicaquixada.edu.br.dia_diagnsticodeincidentalomaadrenal;

private EditText txtDVP, txtDT, txtDSC;
private Button btnCalcular, btnLimpar;

private double dvp, dt, dsc;
private String wr, wa;
private TextView firstPercent, secondPercent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_calc);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setTitle("Sair");

    txtDVP = (EditText) findViewById(R.id.txtDVP);
    txtDT = (EditText) findViewById(R.id.txtDT);
    txtDSC = (EditText) findViewById(R.id.txtDSC);
    btnCalcular = (Button) findViewById(R.id.btnCalcular);
    btnCalcular.setOnClickListener(this);
    btnLimpar = (Button) findViewById(R.id.btnLimpar);
    btnLimpar.setOnClickListener(this);
    firstPercent = (TextView) findViewById(R.id.textView54);
    secondPercent = (TextView) findViewById(R.id.textView55);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()){
        case android.R.id.home:
            startActivity(new Intent(this, MainActivity.class));
            finishAffinity();
            break;
        default:break;
    }
    return true;
}

@Override
public void onClick(View view) {
    if (view.equals(btnCalcular)){
        if (txtDVP.getText().toString().equals("") || txtDT.getText().toString().equals("") || txtDSC.getText().toString().equals("")){
              wa = "0,00%";
              wr = "0,00%";
        }else {
              dvp = Double.parseDouble(txtDVP.getText().toString());
              dt = Double.parseDouble(txtDT.getText().toString());
              dsc = Double.parseDouble(txtDSC.getText().toString());
              wa = String.valueOf(washoutAbsoluto(dvp,dt,dsc));
              secondPercent.setText(wa+"%");
              wr = String.valueOf(washoutRelativo(dvp,dt));
              firstPercent.setText(wr+"%");
        }

    }else if (view.equals(btnLimpar)){

        firstPercent.setText("0,00%");
        secondPercent.setText("0,00%");
        txtDVP.setText("");
        txtDT.setText("");
        txtDSC.setText("");

    }
}

private double washoutAbsoluto (double densidadeVenosaPortal, double densidadeTardia, double densidadeSemContraste){
        double wa = 100*((densidadeVenosaPortal-densidadeTardia)/(densidadeVenosaPortal-densidadeSemContraste));
        return arredondaValores(wa);
}

private double washoutRelativo (double densidadeVenosaPortal, double densidadeTardia){
        double wr = 100*((densidadeVenosaPortal-densidadeTardia)/(densidadeVenosaPortal));
        return arredondaValores(wr);
}

private double arredondaValores (double valorArredondar){
    DecimalFormat formatador = new DecimalFormat("0.00");
    valorArredondar = Double.parseDouble(formatador.format(valorArredondar));
    return valorArredondar;
}
  • 1

    Have you managed to capture any exceptions? Where exactly in your code the error happens?

  • 1

    Start by opening the window Logcat and see the mistake you made, and put the error in the question to help you get answers.

  • @Leandroangelo, the error happens when I put to calculate. I enter the values. The error only happens in a physical device.

  • 1

    Open the Logcat window. There you have a lot of information including the point where the exception occurred and the reason.

No answers

Browser other questions tagged

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