我想在kotlin
創建使用anko
庫表像下面造成的:android.database.sqlite.SQLiteException:近「組織」:語法錯誤(代碼1):在編譯:
override fun onCreate(db: SQLiteDatabase?) {
db!!.createTable(PersonTable.Name, true,
Pair(PersonTable.ID, INTEGER + PRIMARY_KEY + AUTOINCREMENT),
Pair(PersonTable.PersonName, TEXT),
Pair(PersonTable.Domain, TEXT),
Pair(PersonTable.MobileNumber, REAL))
}
當我將AUTOINCREMENT
添加到ID時,出現以下錯誤。它的工作原理沒有AUTOINCREMENT
。使用anko
庫可以使任何屬性成爲AUTOINCREMENT
的方法是什麼?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.williamsro.fourthdemo, PID: 4799
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.williamsro.fourthdemo/com.williamsro.fourthdemo.MainActivity}: android.database.sqlite.SQLiteException: near "org": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS `Person`(id INTEGER PRIMARY KEY [email protected], person_name TEXT, domain TEXT, mobile_number REAL);
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.database.sqlite.SQLiteException: near "org": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS `Person`(id INTEGER PRIMARY KEY [email protected], person_name TEXT, domain TEXT, mobile_number REAL);
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1675)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1606)
at org.jetbrains.anko.db.DatabaseKt.createTable(Database.kt:80)
at com.williamsro.fourthdemo.AppDbHelpler.onCreate(AppDbHelpler.kt:17)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at org.jetbrains.anko.db.ManagedSQLiteOpenHelper.openDatabase(Database.kt:166)
at org.jetbrains.anko.db.ManagedSQLiteOpenHelper.use(Database.kt:157)
at com.williamsro.fourthdemo.MainActivity.insertPerson(MainActivity.kt:44)
at com.williamsro.fourthdemo.MainActivity.onCreate(MainActivity.kt:72)
at android.app.Activity.performCreate(Activity.java:6664)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
添加字符串PersonTable.ID =「你的名字和所有」;等所有在這裏 –
@parikdhakan你是什麼意思? –
如果你看到我的代碼,就沒有這種東西。我相信'AUTOINCREMENT'正在被'org.jetbrains.anko.db.SqlTypeModifierImpl @ 7d0b905'取代' –