我遇到了這段代碼的問題。第6行的if語句在執行過程中被忽略。此時我已經通過了代碼,變量文件[position]的值是「subjects.dat」。然而,它正在跳過這個步驟並轉到相關的else語句。任何想法爲什麼?如果在執行過程中語句被跳過
dialogButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (markComplete.isChecked()) {
String toDelete;
String[] files = fileList();
if (files[position] == "subjects.dat") { //the error occurs at this line
toDelete = files[position + 1];
boolean deleted = deleteFile(toDelete);
if (deleted) {
dialog.dismiss();
} else {
// Do nothing
}
} else {
toDelete = files[position];
boolean deleted = deleteFile(toDelete);
if (deleted) {
dialog.dismiss();
} else {
//Do nothing
}
}
}
}
謝謝!
,因爲它被評價爲假的字符串比較沒有這樣做方式 – njzk2 2013-02-11 16:49:11
@RyanThames isEquals()???你的意思是等於()? – PermGenError 2013-02-11 16:53:18
這可能是最常見的java錯誤之一,以及'if(var = 2)';) – nicopico 2013-02-11 16:53:50