Is giving error in (valorG) inside my IF in all parentheses there IF what can be?

Asked

Viewed 72 times

0

package com.example.testetrabalho;

import androidx.appcompat.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 {

    //variaveis
    EditText editTextValorG;
    EditText editTextValorL;
    EditText editTextValorP;
    Button btnCalcula;
    private EditText textViewMostra;
    private TextView textViewtMostra;

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

        editTextValorG = (EditText) findViewById(R.id.editTextValorG);
        editTextValorL = (EditText) findViewById(R.id.editTextValorL);
        editTextValorP = (EditText) findViewById(R.id.editTextValorP);
      //  textViewMostra = (TextView) findViewById(R.id.textViewMostra);
        btnCalcula = (Button) findViewById(R.id.btnCalcula);


        //funçao do botao calcular

        btnCalcula.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                double valorG = Double.parseDouble(editTextValorL.getText().toString());
                double valorL = Double.parseDouble(editTextValorL.getText().toString());
                double valorP = Double.parseDouble(editTextValorP.getText().toString());


                //IF

                if ((valorG < valorL) && (valorG < valorP))
                    textViewMostra.setText(valorG);

                else if ((valorL < valorG) && (valorL < valorP))
                    textViewMostra.setText(valorL);

                else if ((valorP < valorG) && (valorP < valorL))
                    textViewMostra.setText(valorP);


            }


        });
    }

}
  • It would help if you put together the error messages and value of stack trace. But looking over try this here textViewMostra.setText(String.valueOf(valorG)); or else on the line double valorG = Double.parseDouble(editTextValorL.getText().toString()); change to String valorG = editTextValorL.getText(); and do the same for valorL and valorP. Also to question the need for variables valorG, valorL and valorP in your code as you can do 'textViewMostra.setText(editTextValorL.gettext();' and the same with valorL and valorP.

  • I’ll adjust it, thanks.

  • The error that gives would be read in the variables between() the if gets the red dashes below and says Cannot resolve method 'setText(double)'

  • This error is happening because setText does not accept a double, see here the accepted types https://developer.android.com/reference/android/widget/TextView.html#setText

No answers

Browser other questions tagged

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