Here’s my code:
String Attr = parser.getAttributeValue(null, "name");
String Text = parser.getText();
if (Attr == "id"){
parser.nextTag();
}else if(Attr == "Lektion"){
vocable.setUnit(Text);
parser.nextTag();
}else if(Attr == "Russisch"){
vocable.setRussian(Text);
parser.nextTag();
}else if(Attr == "Umschrift"){
vocable.setTranscript(Text);
parser.nextTag();
}else if(Attr == "Einzelwort"){
int tf = Integer.parseInt(Text);
Boolean bool = null;
switch (tf){
case 0:
bool= false;
break;
case 1:
bool= true;
break;
}
vocable.setSingleWord(bool);
parser.nextTag();
}else if(Attr == "Deutsch"){
vocable.setGerman(Text);
parser.nextTag();
}
the structure of my xml file:
<database name="russisch">
<table name="vokabel">
<column name="Lektion">1</column>
<column name="id">1</column>
<column name="Russisch">Как дела?</column>
<column name="Umschrift">kak dilá</column>
<column name="Deutsch">Wie geht’s?</column>
<column name="Einzelwort">0</column>
</table>
<table name="vokabel">
<column name="id">2</column>
<column name="Lektion">1</column>
<column name="Russisch">Очень хорошо!</column>
<column name="Umschrift">ótschin charaschó</column>
<column name="Deutsch">Sehr gut!</column>
<column name="Einzelwort">0</column>
</table>
</database>
If i’m trying to compare the attribute values with the given ones it never returns true and therefore the if statement never gets executed. I tried to set the sring manually and it worked. Therefore i asume i just have to format the returned string, but i don’t know how. I’m realy hoping somebody can help
You cannot compare Strings with the equals operator:
since String is an object. The equals operator tests whether two objects are the same object so you are comparing Attr with “Einzelwort” which is not the same object.
Instead, use the equals() method which compares the string value of a String.