在Android上创建表时出错

时间:2010-08-22 02:56:37

标签: android database sqlite android-emulator

我正在尝试在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是管理数据库的类。

2 个答案:

答案 0 :(得分:1)

auto_increment更改为autoincrement,您应该做得很好。语法错误简单:)

答案 1 :(得分:1)

count INTEGER not null auto_increment

中存在两个问题
  1. 如smith324所述,auto_increment拼写错误
  2. 更重要的是,count必须是主键,如果你想通过sqlite规则自动增加它。