Myapp的Android Studio问题已停止工作

时间:2017-03-04 11:51:42

标签: android sqlite android-sqlite

所以,我决定使用sqlite数据库创建一个应用程序。然后添加一个添加按钮,但点击它时,我有一条消息("应用程序已停止工作")。下面我将给出logcat详细信息:03-04 11:35:09.210 17673-17673 / com.a00003454.tyreshopapp E / AndroidRuntime:FATAL EXCEPTION:main

  

流程:com.a00003454.tyreshopapp,PID:17673                                                                              java.lang.RuntimeException:无法启动活动   ComponentInfo {com.a00003454.tyreshopapp / com.a00003454.tyreshopapp.AllTyresActivity}:   android.database.sqlite.SQLiteException:near" table":语法错误   (代码1):,编译时:CREATE TABLE Tyre.table(ID INTEGER   PRIMARY KEY AUTOINCREMENT,TyreBrand TEXT Size INTEGER Cost INTEGER);                                                                                  在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)                                                                                  在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)                                                                                  在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                                  在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                                  在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                  在android.os.Looper.loop(Looper.java:148)                                                                                  在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                  at java.lang.reflect.Method.invoke(Native Method)                                                                                  在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                  在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)                                                                               引起:android.database.sqlite.SQLiteException:near" table":   语法错误(代码1):,编译时:CREATE TABLE Tyre.table(ID   INTEGER PRIMARY KEY AUTOINCREMENT,TyreBrand TEXT Size INTEGER Cost   整数 );                                                                                  在   android.database.sqlite.SQLiteConnection.nativePrepareStatement(母语   方法)                                                                                  在   android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)                                                                                  在   android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)                                                                                  在   android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)                                                                                  在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)                                                                                  在   android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31)                                                                                  在   android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1674)                                                                                  在   android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)                                                                                  在   com.a00003454.tyreshopapp.TyreDatabaseHelper.onCreate(TyreDatabaseHelper.java:33)                                                                                  在   android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)                                                                                  在   android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)                                                                                  在   com.a00003454.tyreshopapp.TyreDatabaseHelper.select(TyreDatabaseHelper.java:59)                                                                                  在   com.a00003454.tyreshopapp.AllTyresActivity.onCreate(AllTyresActivity.java:28)                                                                                  在android.app.Activity.performCreate(Activity.java:6237)                                                                                  在   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)                                                                                  在   android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)                                                                                  在   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)                                                                               在android.app.ActivityThread.-wrap11(ActivityThread.java)                                                                                  在   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)                                                                                  在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                  在android.os.Looper.loop(Looper.java:148)                                                                                  在android.app.ActivityThread.main(ActivityThread.java:5417)                                                                                  at java.lang.reflect.Method.invoke(Native Method)                                                                                  在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                                                  在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)03-04   11:35:12.643 17673-17673 / com.a00003454.tyreshopapp I / Process:发送   信号。 PID:17673 SIG:9

1 个答案:

答案 0 :(得分:2)

您创建表的SQL查询不正确

而不是

CREATE TABLE Tyre.table(ID INTEGER PRIMARY KEY AUTOINCREMENT, TyreBrand TEXT Size INTEGER Cost INTEGER );

你应该写

CREATE TABLE Tyre (ID INTEGER PRIMARY KEY AUTOINCREMENT, TyreBrand TEXT Size INTEGER Cost INTEGER )