SUPLMMM
SUPLMMM

Reputation: 13

The operator | is undefined for the argument type(s) boolean, void

Hi i just keep getting that error and im kind of a newbie and dont know wahats going on. Thanks for the help in advance

            if(txtvi1.getText().toString().equals("") | txtvi2.getText().toString().equals("") | txtvi3.getText().toString().equals("") | txtvi4.getText().toString().equals("")| txtvi5.getText().toString().equals("") | txtvi6.getText().toString().equals("") | txtvi7.getText().toString().equals("") | txtvi8.getText().toString().equals("") |  checkbx1.setChecked(false)) {
                    Toast.makeText(getApplicationContext(),  string, 5000).show();

                } else {
                    Toast.makeText(getApplicationContext(), string2, 5000).show();
                }

So the error is in the checkbox i just want the toast to appear if any of the textview are empty or if the checkbox is unchecked. If it is possible how can i do it?

Upvotes: 0

Views: 2059

Answers (2)

Lucifer
Lucifer

Reputation: 29670

You have written a single pipe sign | for OR condition, which is wrong.

When you need to use AND or OR conditional operator in if condition, they should be like as AND = && and OR = ||

so your code needs to be updated as follows,

if( txtvi1.getText().toString().equals("") || txtvi2.getText().toString().equals("") || txtvi3.getText().toString().equals("") || txtvi4.getText().toString().equals("") || txtvi5.getText().toString().equals("") || txtvi6.getText().toString().equals("") || txtvi7.getText().toString().equals("") || txtvi8.getText().toString().equals("") ||  !checkbx1.isChecked() ) 
                {
                    Toast.makeText(getApplicationContext(),  string, 5000).show();
                } 
                else 
                {
                    Toast.makeText(getApplicationContext(), string2, 5000).show();
                }

Upvotes: 3

Shankar Agarwal
Shankar Agarwal

Reputation: 34775

You must use isChecked() function to check whether it is checked or nor.

 if(txtvi1.getText().toString().equals("") || txtvi2.getText().toString().equals("") || txtvi3.getText().toString().equals("") || txtvi4.getText().toString().equals("")|| txtvi5.getText().toString().equals("") || txtvi6.getText().toString().equals("") || txtvi7.getText().toString().equals("") || txtvi8.getText().toString().equals("") ||  !checkbx1.isChecked()) {
                    Toast.makeText(getApplicationContext(),  string, 5000).show();

                } else {
                    Toast.makeText(getApplicationContext(), string2, 5000).show();
                }

Upvotes: 1

Related Questions