这段代码的问题似乎是if语句的'else'部分被执行,即使变量匹配(所以'if'为真)。有什么建议吗?
谢谢!
public void CheckInstalledDBVersion() throws NullPointerException, IOException {
try {
//TRY TO OPEN DATABASE AND READ VERSION
//WRITE VERSION TO InstalledDBversion
} catch(RuntimeException e) {
//IF TABLE COULD NOT BE QUERIED
//SET InstalledDBversion to Bogus value
InstalledDBversion = "00";
Log.d("RTE", ".. but we've catched it!");
} finally {
if (InstalledDBversion.equals(PackedDBversion)){
// Installed DBVersion == Packed DBVersion .. nothing happens
}
else
showDialog(DBCHECKFAILDIALOG);
initialiseDatabase = false;
copyDB();
}
}
因此,当我执行时,即使copyDB();
InstalledDBversion.equals(PackedDBversion) == true
也会被调用
答案 0 :(得分:1)
else
showDialog(DBCHECKFAILDIALOG);
initialiseDatabase = false;
copyDB();
为您修复缩进。 copyDB
位于if/then/else
区块之外。使用带代码格式的IDE。
答案 1 :(得分:0)
else块中应该包含哪些行? showDialog(DBCHECKFAILDIALOG)
仅包括在内。你是否错过了一组{}
的else块?