Kra*_*axi 1 eclipse sqlite android
我在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);
}
Run Code Online (Sandbox Code Playgroud)
当我调用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(?, ?, ?, ?, ?, ?);
Run Code Online (Sandbox Code Playgroud)
您有任何解决方法的想法吗?我知道有几个这样的主题,但是没有一个解决方案对我有帮助。
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); ";
Run Code Online (Sandbox Code Playgroud)
我猜列名和它的类型之间没有空格。KEY_B + "text, "在文本之前(此处和其他列)放置一个空格。
并且不要忘记在那之后删除数据库(从手机中卸载应用程序)!
| 归档时间: |
|
| 查看次数: |
4369 次 |
| 最近记录: |