我正在尝试在android数据库中创建一个表,但是当我尝试运行该应用程序时,LogCat会返回以下错误:
08-22 02:39:29.098:ERROR / AndroidRuntime(277):引起:android.database.sqlite.SQLiteException:接近“auto_increment”:语法错误:CREATE TABLE字(id INTEGER PRIMARY KEY,word TEXT, count INTEGER not null auto_increment)
此错误的代码是:
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, word TEXT, count INTEGER not null auto_increment)");
}
此线上也有错误,箭头之间的错误:
public DataHelper(Context context) {
this.context = context;
OpenHelper openHelper = new OpenHelper(this.context);
-->this.db = openHelper.getWritableDatabase();<--
this.insertStmt = this.db.compileStatement(INSERT);
this.updateStmt = this.db.compileStatement(UPDATE);
}
Ps:之前的代码来自DataHelper类。
和erro在这一行(logcat只是说类的行,不要说错误):
this.dh = new DataHelper(this);
Ps:DataHelper是管理数据库的类。
答案 0 :(得分:1)
将auto_increment
更改为autoincrement
,您应该做得很好。语法错误简单:)
答案 1 :(得分:1)
count INTEGER not null auto_increment
auto_increment
拼写错误count
必须是主键,如果你想通过sqlite规则自动增加它。