gpt4 book ai didi

创建表时出现 Android SQLite 错误

转载 作者:太空狗 更新时间:2023-10-29 16:06:22 26 4
gpt4 key购买 nike

我正在尝试使用 SQLiteOpenHelper 创建新数据库。

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("CREATE TABLE SecretNumbers ("
+ "id integer primary key autoincrement, "
+ "PhoneNumber text);");

sqLiteDatabase.execSQL("CREATE TABLE SecretWords ("
+ "id integer primary key autoincrement, "
+ "SecretWord text);");

sqLiteDatabase.execSQL("CREATE TABLE SecretSMS ("
+ "id integer primary key autoincrement, "
+ "from text, "
+ "body text, "
+ "receivedatetime text, "
+ "isunread integer );" );



}

在运行时我遇到了以下错误。有人可以帮我解决这个问题吗?

11-25 22:57:23.329: INFO/Database(1231): sqlite returned: error code = 1, msg = near "from": syntax error
11-25 22:57:23.329: ERROR/Database(1231): Failure 1 (near "from": syntax error) on 0x2aaaf0 when preparing 'CREATE TABLE SecretSMS (id integer primary key autoincrement, from text, body text, receivedatetime text, isunread integer );'.
11-25 22:57:23.349: ERROR/SQLiteOpenHelper(1231): Couldn't open SecretPhoneDatabase for writing (will try read-only):
android.database.sqlite.SQLiteException: near "from": syntax error: CREATE TABLE SecretSMS (id integer primary key autoincrement, from text, body text, receivedatetime text, isunread integer );
at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
at net.cgrup.SecretPhone.DataBase.DbHelper.onCreate(DbHelper.java:29)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
at net.cgrup.SecretPhone.Broadcast.SmsReceiver.onReceive(SmsReceiver.java:31)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
11-25 22:57:23.369: WARN/dalvikvm(1231): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-25 22:57:23.399: ERROR/AndroidRuntime(1231): FATAL EXCEPTION: main
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.provider.Telephony.SMS_RECEIVED (has extras) } in net.cgrup.SecretPhone.Broadcast.SmsReceiver@4051d190
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/net.cgrup.SecretPhone/databases/SecretPhoneDatabase
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:199)
at net.cgrup.SecretPhone.Broadcast.SmsReceiver.onReceive(SmsReceiver.java:31)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
... 9 more

最佳答案

from 是一个 SQL 关键字。您可能希望避免将其用作列名。如果您必须使用该名称,请按照此处所述将其转义:http://www.sqlite.org/lang_keywords.html

关于创建表时出现 Android SQLite 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13555494/

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