0

I have a variable which i obtain from another class. I then run a != "" check in an IF statement. On the summary2, the value should be "" and so the if statement should go to else but it does not.

    getArticle data = getArticle.getMyData();

    if (data.summary1 != "") {
        tvSummary1.setText(data.summary1);
    } else {
        tvSummary1.setVisibility(View.GONE);
    }

    if (data.summary2 != "") {
        tvSummary2.setText(data.summary2);
    }else {
        tvSummary2.setVisibility(View.GONE);
    }

This is what i get when debugging:

Image

  • 2
    You're comparing strings with !=. This checks if they are literally the same string (as opposed to containing the same letters). Use the equals function instead – Richard Tingle Jul 15 '14 at 23:09
  • Btw, I recommend using an IDE (such as eclipse) for this sort of thing. In any good IDE you would have gotten warnings about this – Richard Tingle Jul 15 '14 at 23:12
  • @RichardTingle Thanks. I dont think i got any warnings and i am using Eclipse. Must check my settings. – jamesgates1 Jul 15 '14 at 23:14
  • I'm ready to see a month asking ban for those who ask this. It's mind boggling this gets asked *at least* once a day. The answer can be found in *any* formal reference for Java, and endless links on the [Google](https://www.google.com/search?q=%3D%3D+and+!%3D+with+Java+Strings&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&channel=fflb)! – ChiefTwoPencils Jul 15 '14 at 23:46

0 Answers0