I trying to connect my Android application to a database on remote host.
I want to use the records of the DB, but there’s a problem when i try to do this:
if(buffer.toString()=="OPEN")
{
button_signal.setText("OPEN");
}
else
{
button_signal.setText("CLOSE");
}
I have checked buffer.toString() using Logs, and it is equal to “OPEN”, but the button_signal’s text is printed “CLOSE”. Why? Can you help me?
You can’t compare String with the “==” Operator in Java. A String is an Object.
Try this buffer.toString().equals(“OPEN”);
EDIT:
Even better is if you compare it like this: “OPEN”.equals(buffer.toString())
Because it won’t throw an exception if buffer is null.