Possible Duplicate:
Syntax Question IF ELSE (Java)
I am trying to make a calculator which shows a message if no value is entered in editbox. But it FC’s!! I am making apps after long time so I am quite confused.
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v) {
double a=0;
double b=0;
double c=0;
EditText edit;
EditText edit2;
TextView edit3;
String lname="";
edit=(EditText)findViewById(R.id.edit);
edit2=(EditText)findViewById(R.id.edit2);
edit3=(TextView)findViewById(R.id.edit3); // everything defined above
String editstr= edit.getText().toString(); // real work starts
if(editstr.contentEquals(lname))
edit3.setText("Enter value");
else
a=Double.parseDouble(edit.getText().toString()); // else add the stuff
b=Double.parseDouble(edit2.getText().toString());
c=a+b;
edit3.setText(Double.toString(c));
} };
put brackets around your if-else, currently in case of else it only executes the first line, other lines are executed no matter if your if passes or fails.