So, i’m trying to parse some xml that looks this way:
<image size="extralarge">
http://...
</image>
But I can’t manage to compare the value of attr with a String.
Here’s my code :
albumImage.setTextElementListener(new TextElementListener() {
boolean imageGoodSize=true;
@Override
public void start(Attributes attributes) {
Log.v(TAG_LASTFM, "Image #" + attributes.getValue("size") + "#");
if(attributes.getValue("size")+"" == "extralarge" || attributes.getValue("size")+"" == "mega") {
imageGoodSize=false;
Log.w(TAG_LASTFM, "(imageGoodSize set to false");
}
else {
imageGoodSize=true;
}
}
In the log, it shows that size is set to “extralarge”, But when i try to compare it to the string “extralarge”, imageGoodSize isn’t set to false. What am I doing wrong ?
Here is the log :
06-21 01:52:30.463: V/ParseMusic_LastFM(32610): Image #extralarge#
You should not compare Strings in Java with the
==operator. You need to use.equals("extralarge")==compare the reference to the String, whereas.equalscompare the content.