0
我試圖在從數據庫填充的組合框中使用數據密鑰對。更新數據庫中的記錄。
我能夠用數據庫中的數據填充組合框,但是當我使用組合框中的數據更新記錄時,如果組合框的選擇索引爲空,我收到一個錯誤,指出我有空指針。
我想設計一種方法來檢查框是否爲空,以便如果它是我不使用它的更新。
我完全沉迷於此。
這裏是我到目前爲止檢查空值並運行更新如果值不爲空的代碼。這些更新本身是可以工作的,但是當我嘗試從組合框中獲取數據時,我必須轉換數據類型並且沒有選擇任何內容,所以我收到錯誤消息。從SWT組合框中獲取數據
public Boolean checkStrNull(String strTest) {
if (strTest == null) {
return false;
} else if (strTest.isEmpty()) {
return false;
} else if (strTest == "") {
return false;
} else {
return true;
}
}
public Boolean checkIntNull(int intTest) {
if (intTest == 0) {
return false;
} else {
return true;
}
}
public void updateIntAnimal(Animal a, String strField, Integer intNew)
throws SQLException {
if (checkIntNull(intNew)) {
a.updateIntField(strField, intNew);
}
}
public void updateStrAnimal(Animal a, String strField, String strNew)
throws SQLException {
if (checkStrNull(strNew)) {
a.updateStrField(strField, strNew);
}
}
謝謝你做到了。 – Talon06