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