-3

I have dead code warning at this position:

if("Email" == "+email.getText().toString()+"){
  Toast.makeText(getApplicationContext(), "email_id already available ", Toast.LENGTH_SHORT).show();
} 

Can anyone help?

laalto
  • 150,114
  • 66
  • 286
  • 303

5 Answers5

4

if("Email" == "+email.getText().toString()+")

"Email" can never be equal to "+email.getText().toString()+"

You probably wanted to write

if("Email" == email.getText().toString())  

and you should use the equal-Method to compare Strings:

if("Email".equals(email.getText().toString()))  

You'll find more informations about comparing Strings in Java HERE

Community
  • 1
  • 1
B. Kemmer
  • 1,517
  • 1
  • 14
  • 32
  • yep it would work. but it definitely is bad code. you should use equal to compare Strings or Objects in java – B. Kemmer Jun 03 '15 at 09:06
4

"Email" will never be equal to "+email.getText().toString()+". I think you wanted to use:

if ("Email".equals(email.getText().toString()))

albertoqa
  • 525
  • 3
  • 11
3

It should be

 if("Email".equals(mail.getText().toString()))
    {
     Toast.makeText(getApplicationContext(), "email_id already available ", Toast.LENGTH_SHORT).show(); 
    }
N J
  • 27,217
  • 13
  • 76
  • 96
0

Replace "Email" == "+email.getText().toString()+" with "Email".equals(email.getText().toString())

Strings should always be compared using the equals() method.'

Also, consider defining constants, e.g.

public static final String KEY_EMAIL = "Email"

then use

if(email.getText().toString().equals(KEY_EMAIL)) {...}
SlashG
  • 671
  • 4
  • 17
0

you should use

if(email.getText().toString().equals("Email"){ 
 Toast.makeText(getApplicationContext(), "email_id already available ", Toast.LENGTH_SHORT).show(); 
}

or use ignoreCaseEquals, explanation why it is dead code you must know by now by reading above answers

Syed Raza Mehdi
  • 4,067
  • 1
  • 31
  • 47