如何在数据库应用程序中使用android studio解决此错误

时间:2017-01-02 21:53:30

标签: android

01-03 02:22:33.126 19890-19890/com.example.waleed.database_task E/SQLiteLog: (1) near "create_tableStudent_table": syntax error
01-03 02:22:33.146 19890-19890/com.example.waleed.database_task D/AndroidRuntime: Shutting down VM
01-03 02:22:33.146 19890-19890/com.example.waleed.database_task W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4187de48)
01-03 02:22:33.156 19890-19890/com.example.waleed.database_task E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.waleed.database_task, PID: 19890
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.waleed.database_task/com.example.waleed.database_task.MainActivity}: android.database.sqlite.SQLiteException: near "create_tableStudent_table": syntax error (code 1): , while compiling: create_tableStudent_table (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
      at android.app.ActivityThread.access$800(ActivityThread.java:139)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5103)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
      at dalvik.system.NativeStart.main(Native Method)
   Caused by: android.database.sqlite.SQLiteException: near "create_tableStudent_table": syntax error (code 1): , while compiling: create_tableStudent_table (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)
      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:892)
      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:503)
      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:726)
      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:1773)
      at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1704)
      at com.example.waleed.database_task.Databasehelper.onCreate(Databasehelper.java:31)
      at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
      at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
      at com.example.waleed.database_task.Databasehelper.<init>(Databasehelper.java:25)
      at com.example.waleed.database_task.MainActivity.onCreate(MainActivity.java:27)
      at android.app.Activity.performCreate(Activity.java:5275)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252) 
      at android.app.ActivityThread.access$800(ActivityThread.java:139) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:136) 
      at android.app.ActivityThread.main(ActivityThread.java:5103) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606) 
      at dalvik.system.NativeStart.main(Native Method) 
01-03 02:22:34.678 19890-19890/com.example.waleed.database_task I/Process: Sending signal. PID: 19890 SIG: 9

1 个答案:

答案 0 :(得分:0)

create_tableStudent_table (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)

这不是有效的SQL语句。这将是:

create _tableStudent_table (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,SURNAME TEXT,MARKS INTEGER)

必须使用空格将CREATE关键字与表名分开。