![](/img/trans.png)
[英]compare xml files by choosing specific tag name for comparison, list attribute difference of that specific tag
[英]Can't compare an attribute from a xml tag
因此,我試圖解析看起來像這樣的xml:
<image size="extralarge">
http://...
</image>
但是我無法將attr的值與String進行比較。 這是我的代碼:
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;
}
}
在日志中,它顯示大小設置為“ extralarge”,但是當我嘗試將其與字符串“ extralarge”進行比較時,imageGoodSize並未設置為false。 我究竟做錯了什么 ?
這是日志:
06-21 01:52:30.463: V/ParseMusic_LastFM(32610): Image #extralarge#
您不應將Java中的字符串與==
運算符進行比較。 您需要使用.equals("extralarge")
==
比較對字符串的引用,而.equals
比較內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.