jeudi 19 mars 2015

The operator ! is undefined for the argument type(s) String java(Android)

I am using android and had an email field(EditText) from which i will fetch data, if we not entered data in to that field and press ok then i should display a dialog


Sample Code



final EditText input = new EditText(this);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String email = input.getText().toString();
Log.v("><><><><><><>",email);
if (email == null)
{
AlertDialog.Builder alert_email = new AlertDialog.Builder(MainActivity.this);

alert_email.setMessage("Please enter email.");
alert_email.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert_email.show();
}
else
{
...........
...........
}
}
});


When i used if(!email) it was displaying error as The operator ! is undefined for the argument type(s) String java(Android) but when used used null as above and it was not coming in to if block and always going to else block


So how to check if the variable has data in java ?


Guys don't downvote it, as i am new to java


Aucun commentaire:

Enregistrer un commentaire