gpt4 book ai didi

android - 编译时由: android. database.sqlite.SQLiteException : near "org": syntax error (code 1): ,引起:

转载 作者:搜寻专家 更新时间:2023-11-01 08:26:30 28 4
gpt4 key购买 nike

我正在尝试使用 kotlin 中的 anko 库创建表,如下所示

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 org.jetbrains.anko.db.SqlTypeModifierImpl@7d0b905, 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 org.jetbrains.anko.db.SqlTypeModifierImpl@7d0b905, 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)

最佳答案

看来您使用的是过时版本的 Anko。在 0.10 版本中,连接修饰符的问题已得到修复,并在 0.10.1 版本中再次恢复。

在代码的相关部分之前是 "$modifier $m" 其中 $m 是修饰符的字符串表示形式。由于它没有定义 toString() 方法,因此使用实例的 Java 表示。

修复后代码为 "$modifiers ${m.modifier}"。这里的${m.modifier}实际上是一个字符串。

如果最新的修复与您无关,请使用版本 0.10

关于android - 编译时由: android. database.sqlite.SQLiteException : near "org": syntax error (code 1): ,引起:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44491674/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com