即使string.equals(otherstring)为true,其他部分代码也会被执行

时间:2011-11-22 08:36:23

标签: try-catch equals if-statement finally

这段代码的问题似乎是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也会被调用

2 个答案:

答案 0 :(得分:1)

else
   showDialog(DBCHECKFAILDIALOG);

initialiseDatabase = false;
copyDB();

为您修复缩进。 copyDB位于if/then/else区块之外。使用带代码格式的IDE。

答案 1 :(得分:0)

else块中应该包含哪些行? showDialog(DBCHECKFAILDIALOG)仅包括在内。你是否错过了一组{}的else块?