我已经浏览了几个关于列不存在错误的问题,大多数都是间距问题或与模式有关的问题,这可以通过修复卸载并重新安装应用程序。我校对了我的声明,并尝试从我的手机中卸载应用程序,然后从android studio重新下载。似乎也没有解决我的问题。SQLite数据库列不存在
这里该行引发错误:
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + DATE_TO_REMIND + "='" + date + "'", null);
它的意图是把表中的每个元素(其列同行),有这是一个参数,我想要的日期( 。我有方法(getWordsToReview)
我不断收到错误是这样的:
Caused by: android.database.sqlite.SQLiteException: no such column: Date_To_Remind (code 1): , while compiling: SELECT * FROM Vocabulary WHERE Date_To_Remind='2016/03/05'
该类的其余部分是这样的:
public class DBHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "vocab.db";
public static final String VOCAB_INPUT = "Input_Word";
public static final String VOCAB_TRANSLATION = "Translation";
public static final String DATE_TO_REMIND = "Date_To_Remind";
public static final String TABLE_NAME = "Vocabulary";
public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME + "("
+ VOCAB_INPUT + " TEXT "
+ VOCAB_TRANSLATION + " TEXT "
+ DATE_TO_REMIND + " TEXT"
+ ");";
db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public void addWord(Word word) {
ContentValues values = new ContentValues();
values.put(VOCAB_INPUT, word.getWord());
values.put(VOCAB_TRANSLATION, word.getTranslation());
values.put(DATE_TO_REMIND, word.getDate());
SQLiteDatabase db = getWritableDatabase();
db.insert(TABLE_NAME, null, values);
db.close();
}
public void deleteWord(Word word) {
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_NAME + " WHERE " + VOCAB_INPUT + "=\"" + word.getWord() + "\"");
}
public List<Word> getWordsToReview(String date) {
List<Word> returnWords = new ArrayList<>();
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + DATE_TO_REMIND + "='" + date + "'", null);
while (cursor.moveToNext()) {
String retrievedName = cursor.getString(cursor.getColumnIndex(VOCAB_INPUT));
String retrievedTranslation = cursor.getString(cursor.getColumnIndex(VOCAB_TRANSLATION));
String retrievedDate = cursor.getString(cursor.getColumnIndex(DATE_TO_REMIND));
Word tempWord = new Word(retrievedName, retrievedTranslation, retrievedDate);
returnWords.add(tempWord);
}
cursor.close();
return returnWords;
}
public boolean doesWordExist(Word word) {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + VOCAB_INPUT + "=\"" + word.getWord() + "\"", null);
boolean exists = false;
while (cursor.moveToNext()) {
String retrievedName = cursor.getString(cursor.getColumnIndex(VOCAB_INPUT));
if (retrievedName.equalsIgnoreCase(word.getWord())) {
exists = true;
break;
}
}
cursor.close();
return exists;
}
}
不应该在'onCreate()'中的每个'TEXT'后面加一个逗号来分隔列吗? – PPartisan
另外请注意,您的日期格式不正确。它必须是'2016-03-05'。 –
@BobMalooga你为什么这么说?当我在另一个课程中格式化日期时,日期格式如下:2016/03/05 – NuffsaidM8