Android SQLite Exception 没有这样的列

标签 android eclipse sqlite

我的 Android 应用程序中的数据库有问题。这是一些代码:

private static final String QUESTIONS_TABLE = "questions";
/* questions keys */
public static final String KEY_ROWID = "_id";
public static final String KEY_TYPE = "type";
public static final String KEY_CONTENT = "content";
public static final String KEY_A = "answerA";
public static final String KEY_B = "answerB";
public static final String KEY_C = "answerC";
public static final String KEY_D = "answerD";

private static final String QUESTIONS_TABLE_CREATE = 
    "create table "+ QUESTIONS_TABLE +" (" + KEY_ROWID + " integer primary key autoincrement, "
    + KEY_TYPE + "integer not null,"
    + KEY_CONTENT + " text not null, "
    + KEY_A + " text, "
    + KEY_B + "text, "
    + KEY_C + "text, "
    + KEY_D + "text); ";

//--- QUESTIONS SECTION ---
//--- inserts a close question ---
public long insertCloseQuestion(int type, String content, String[] answers) {
    ContentValues initValues = new ContentValues();
    initValues.put(KEY_TYPE, type);
    initValues.put(KEY_CONTENT, content);
    if(answers != null && answers.length > 0) {
        initValues.put(KEY_A, answers[0]);
        initValues.put(KEY_B, answers[1]);
        initValues.put(KEY_C, answers[2]);
        initValues.put(KEY_D, answers[3]);
    }
    Log.d("VM", initValues.toString());

    return db.insertOrThrow(QUESTIONS_TABLE, null, initValues);
}

当我调用 insertCloseQuestion 方法时,Android 返回异常:

android.database.sqlite.SQLiteException: table questions has no column named answerD: , while compiling: INSERT INTO questions(answerD, content, answerB, answerC, type, answerA) VALUES(?, ?, ?, ?, ?, ?);

你有什么解决办法吗?我知道有几个这样的主题,但没有一个解决方案对我有帮助。

最佳答案

private static final String QUESTIONS_TABLE_CREATE = 
    "create table "+ QUESTIONS_TABLE +" (" + KEY_ROWID + " integer primary key autoincrement, "
    + KEY_TYPE + "integer not null,"
    + KEY_CONTENT + " text not null, "
    + KEY_A + " text, "
    + KEY_B + "text, "
    + KEY_C + "text, "
    + KEY_D + "text); ";

我想列名和它的类型之间没有空格。 KEY_B + "text, " 在文本前放置一个空格(此处和其他列)。

然后不要忘记删除数据库(从手机上卸载应用程序)!

关于Android SQLite Exception 没有这样的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9758957/

相关文章:

Android SoundPool 在播放另一种声音之前不会第二次播放相同的声音

android - 图形布局调色板中缺少小部件(eclipse 上的 android)

python - 在 SQLite 中比较日期

sqlite - 有什么方法可以将整数(十进制形式的 3)转换为 SQLite 中的二进制等效值 11 吗?

javascript - 在 Firefox 中导出 Awesomebar 历史记录

java - Android SignalR java 客户端 : Not receiving all the SignalR messages on the HubConnection

android - 我的应用程序扩展是否会在我的 android 服务之前创建?

java - 当我更改静态文件并重新加载页面时,为什么 spring devtools 不起作用?

java - 条件语句被忽略

java - RecyclerView 项目选择抛出错误