0

我正在尝试在我的 SQLiteOpenHelper 文件中使用它来检查是否存在表和带有 Android 的 SQLite 数据库

// Check to see if a table exists
public boolean isTableExists(String tblName) {
    String existQuery = "SELECT name FROM sqlite_master WHERE name ='" + tblName + "' and type='table'";
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(existQuery, null);

    if(cursor != null){
        cursor.close();
        return true;
    }

    return false;

}

我的活动的电话是

if(db.isTableExists("characters") == false){
        Intent p = new Intent("com.tml.rpgtodo.CREATECHARACTER");
        startActivity(p);
    }

我在 if 语句的行上不断收到 NullPointerException。我究竟做错了什么?

4

1 回答 1

1

db当你打电话时听起来像是null if(db.isTableExists("characters") == false)

我还看到您在“isTableExists()”中初始化了 db。那是一个不同的“db”吗?

于 2012-09-24T02:22:23.260 回答