简体   繁体   English

得到的错误:原因:android.database.sqlite.SQLiteException:附近的“ of”

[英]getting the error : Caused by: android.database.sqlite.SQLiteException: near “of”

i am getting this error : " Caused by: android.database.sqlite.SQLiteException: near "of": syntax error: CREATE TABLE List of Notes (_idINTEGER PRIMARY KEY AUTOINCREMENT, notes_nameTEXT NOT NULL notes_contentTEXT NOT NULL notes_timeTEXT NOT NULL); " 我收到此错误:“引起原因:android.database.sqlite.SQLiteException:在“ of”附近:语法错误:CREATE TABLE注释列表(_idINTEGER主键自动递增,notes_nameTEXT不为空notes_contentTEXT不为空notes_timeTEXT不为空);“

I am using this code: 我正在使用此代码:

 db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + 
                        KEY_ROWID + "INTEGER PRIMARY KEY AUTOINCREMENT, " +
                        KEY_NAME + "TEXT NOT NULL " + 
                        KEY_CONTENT + "TEXT NOT NULL " +
                        KEY_TIME + "TEXT NOT NULL);"

                        );

This is my logcat: 这是我的日志:

  12-17 08:58:15.998: I/Database(515): sqlite returned: error code = 1, msg = near "of": syntax error
    12-17 08:58:15.998: E/Database(515): Failure 1 (near "of": syntax error) on 0x22ddf8 when preparing 'CREATE TABLE List of Notes (_idINTEGER PRIMARY KEY AUTOINCREMENT, notes_nameTEXT NOT NULL, notes_contentTEXT NOT NULL, notes_timeTEXT NOT NULL);'.
    12-17 08:58:16.060: D/AndroidRuntime(515): Shutting down VM
    12-17 08:58:16.068: W/dalvikvm(515): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    12-17 08:58:16.088: E/AndroidRuntime(515): FATAL EXCEPTION: main
    12-17 08:58:16.088: E/AndroidRuntime(515): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.compilationofnotes.pragya/com.compilationofnotes.pragya.NotesView}: android.database.sqlite.SQLiteException: near "of": syntax error: CREATE TABLE List of Notes (_idINTEGER PRIMARY KEY AUTOINCREMENT, notes_nameTEXT NOT NULL, notes_contentTEXT NOT NULL, notes_timeTEXT NOT NULL);
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.os.Handler.dispatchMessage(Handler.java:99)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.os.Looper.loop(Looper.java:123)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.ActivityThread.main(ActivityThread.java:4627)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at java.lang.reflect.Method.invokeNative(Native Method)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at java.lang.reflect.Method.invoke(Method.java:521)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at dalvik.system.NativeStart.main(Native Method)
    12-17 08:58:16.088: E/AndroidRuntime(515): Caused by: android.database.sqlite.SQLiteException: near "of": syntax error: CREATE TABLE List of Notes (_idINTEGER PRIMARY KEY AUTOINCREMENT, notes_nameTEXT NOT NULL, notes_contentTEXT NOT NULL, notes_timeTEXT NOT NULL);
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at com.compilationofnotes.pragya.SqlDatabase$DbHelper.onCreate(SqlDatabase.java:41)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at com.compilationofnotes.pragya.SqlDatabase.open(SqlDatabase.java:62)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at com.compilationofnotes.pragya.NotesView.onCreate(NotesView.java:23)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    12-17 08:58:16.088: E/AndroidRuntime(515):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    12-17 08:58:16.088: E/AndroidRuntime(515):  ... 11 more
    12-17 08:58:18.848: I/Process(515): Sending signal. PID: 515 SIG: 9

This is my new logcat: 这是我的新日志:

12-17 09:27:25.535: D/AndroidRuntime(357): Shutting down VM
12-17 09:27:25.535: W/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-17 09:27:25.578: E/AndroidRuntime(357): FATAL EXCEPTION: main
12-17 09:27:25.578: E/AndroidRuntime(357): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.compilationofnotes.pragya/com.compilationofnotes.pragya.NewNote}: java.lang.NullPointerException
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.os.Looper.loop(Looper.java:123)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-17 09:27:25.578: E/AndroidRuntime(357):  at java.lang.reflect.Method.invokeNative(Native Method)
12-17 09:27:25.578: E/AndroidRuntime(357):  at java.lang.reflect.Method.invoke(Method.java:521)
12-17 09:27:25.578: E/AndroidRuntime(357):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-17 09:27:25.578: E/AndroidRuntime(357):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-17 09:27:25.578: E/AndroidRuntime(357):  at dalvik.system.NativeStart.main(Native Method)
12-17 09:27:25.578: E/AndroidRuntime(357): Caused by: java.lang.NullPointerException
12-17 09:27:25.578: E/AndroidRuntime(357):  at com.compilationofnotes.pragya.NewNote.onCreate(NewNote.java:28)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-17 09:27:25.578: E/AndroidRuntime(357):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-17 09:27:25.578: E/AndroidRuntime(357):  ... 11 more

Please help. 请帮忙。 Thanks in advance! 提前致谢!

Change your create table query as: 将您的创建表查询更改为:

  String CREATE_DATABASE_TABLE = "CREATE TABLE " + DATABASE_TABLE + "("
            + KEY_ROWID + " INTEGER PRIMARY KEY," +
              KEY_NAME  + " TEXT NOT NULL,"
            + KEY_CONTENT + " TEXT NOT NULL," 
            + KEY_TIME + " TEXT NOT NULL"
             + ")";

 db.execSQL(CREATE_DATABASE_TABLE);

you are not putting "," after each column in create table statement 您没有在create table语句的每一列后面加上“,”

On top of the great advice in the other answer. 在另一个答案的最佳建议之上。

CREATE TABLE List of Notes (

A table name must be one word. 表名称必须是一个单词。 Consider ListOfNames , List_of_Names , etc. 考虑ListOfNamesList_of_Names等。

use comma separation in your code 在代码中使用逗号分隔

   db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + 
                    KEY_ROWID + "INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    KEY_NAME + "TEXT NOT NULL, " + 
                    KEY_CONTENT + "TEXT NOT NULL, " +
                    KEY_TIME + "TEXT NOT NULL);"

                    );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 原因:android.database.sqlite.SQLiteException:附近“”:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near “”: syntax error (code 1): 出现错误:由以下原因引起:android.database.sqlite.SQLiteException:靠近“ TABLENAME”语法错误(代码1),编译SELECT查询 - getting error : Caused by: android.database.sqlite.SQLiteException: near “TABLENAME” syntax error (code 1) compiling a SELECT query 原因:android.database.sqlite.SQLiteException:在“ CREATE_TABELLOGIN”附近 - Caused by: android.database.sqlite.SQLiteException: near “CREATE_TABELLOGIN” 错误:引起:android.database.sqlite.SQLiteException:near“add”:语法错误(代码1): - Error: Caused by: android.database.sqlite.SQLiteException: near “add”: syntax error (code 1): 引起:android.database.sqlite.SQLiteException:near“”:语法错误(代码1):,同时编译: - Caused by: android.database.sqlite.SQLiteException: near “”: syntax error (code 1): , while compiling: 由以下原因引起:android.database.sqlite.SQLiteException:在“ org”附近:语法错误(代码1):,而在编译时: - Caused by: android.database.sqlite.SQLiteException: near “org”: syntax error (code 1): , while compiling: 引起:android.database.sqlite.SQLiteException:在“Appliances”附近:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near "Appliances": syntax error (code 1): 原因:android.database.sqlite.SQLiteException:在“ TABLEProject”附近:语法错误(代码1):,而在编译时: - Caused by: android.database.sqlite.SQLiteException: near “TABLEProject”: syntax error (code 1): , while compiling: 造成原因:android.database.sqlite.SQLiteException:“文本”附近:语法错误(代码1): - Caused by: android.database.sqlite.SQLiteException: near “text”: syntax error (code 1): android应用程序崩溃,并显示错误android.database.sqlite.SQLiteException:附近 - android Application crashes with error android.database.sqlite.SQLiteException: near
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM