Kit Ramos
Kit Ramos

Reputation: 1849

Can someone please tell me why this if block is not working right?

Code:

String my = c.getString(c.getColumnIndexOrThrow("ringtype"));
Log.e("my", my);
if(my=="default")
{
    Log.e(tablename, "button marked not visable1");
}
else
{
    Log.e(tablename, "button marked visable2");
}

LogCat:

07-28 02:10:57.396: ERROR/my(16204): default
07-28 02:10:57.404: ERROR/meds(16204): button marked visable2

I also tried Log.e("my", "!"+my+"!"); to see if there was a hidden white space that was throwing it off. but there is not. as far as I can tell the two are a match and I should get the message that the button is not visible.

so I must be missing something but I can't figure out what it is edit: thanks everyone, I'd accept all the answers as they make sense if I could.

Upvotes: 0

Views: 69

Answers (4)

Neetesh
Neetesh

Reputation: 1

You can check with if(my.equals("default"))

Upvotes: 0

ngesh
ngesh

Reputation: 13501

"my" is different object and "default" is another one.. when you use "==" operator it compares the actual address/reference where as ".equals" compares the content.. so use .equals

Upvotes: 3

bhups
bhups

Reputation: 14875

try my.equals("default") instead of my=="default".

Upvotes: 0

Rasel
Rasel

Reputation: 15477

String can't be compared with == USe like if(my.equals("default"))

Upvotes: 3

Related Questions