问题描述
我得到这个错误 -十二月七日至3日:29:18.643:E / SQLiteLog(5181):(1)表帐户没有指定的列otherNotes
I'm getting this error -07-03 12:29:18.643: E/SQLiteLog(5181): (1) table accounts has no column named otherNotes
这是我的code:
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "accountsManager";
private static final String TABLE_ACCOUNTS = "accounts";
private static final String KEY_ID = "id";
private static final String KEY_TITLE = "title";
private static final String KEY_USERID = "userId";
private static final String KEY_PASSWORD = "password";
private static final String KEY_LOGINURL = "loginUrl";
private static final String KEY_OTHERNOTES = "otherNotes";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
String CREATE_ACCOUNTS_TABLE = "CREATE TABLE " + TABLE_ACCOUNTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_TITLE + " TEXT,"
+ KEY_USERID + " TEXT," + KEY_PASSWORD + " TEXT," + KEY_LOGINURL + " TEXT,"
+ KEY_OTHERNOTES + " TEXT" + ");";
db.execSQL(CREATE_ACCOUNTS_TABLE);
}
public void addAccount(AccountDetails account) {
SQLiteDatabase db = this.getWritableDatabase();
System.out.println("Hello!");
ContentValues values = new ContentValues();
values.put(KEY_TITLE, account.getTitle()); // Account Title
values.put(KEY_USERID, account.getUserId()); // account userid
values.put(KEY_PASSWORD, account.getPassword()); // account password
values.put(KEY_LOGINURL, account.getLoginUrl()); // account loginurl
values.put(KEY_OTHERNOTES, account.getOtherNotes()); // account othernotes
Log.v("title", KEY_TITLE);
// Inserting Row
db.insert(TABLE_ACCOUNTS, null, values);
db.close(); // Closing database connection
}
此外,当我删除下面的语句:
Also, when I remove the following statement:
values.put(KEY_OTHERNOTES, account.getOtherNotes()); // account othernotes
然后,我得到了同样的问题,密码等。即,(1)表帐户没有列名为密码
Then I get the same problem with password...etc.i.e, (1) table accounts has no column named password
请帮助!
推荐答案
看来你在数据库中增加了一些列后。我不同意肯狼,你应该考虑卸载并重新安装您的应用程序。一个更好的做法是,删除并重新在的onupdate
方法中的所有表,每次更改架构时增加分贝版本。
It seems that you added some columns later in the database. I do agree with Ken Wolf and you should consider uninstalling and re-installing your app. One better approach is, drop and recreate all tables in onUpdate
method, and increase the db version every time you change the schema.
这篇关于Android的SQLite的问题 - 表......有没有指定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!