-2

当我尝试执行我的应用程序时,它崩溃了,我收到了这个"java.lang.RuntimeException: Unable to start activity ComponentInfo: Sqlite exception"错误。请帮我找出我的错误。这是我的代码的快照:

@Override
public void onCreate(SQLiteDatabase db) {
    this.db = db;
    final String SQL_CREATE_QUESTIONS_TABLE =
            "CREATE TABLE " +
            questiontable.TABLE_NAME + " ( " +
            questiontable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
            questiontable.COLUMN_QUESTION + "TEXT," +
            questiontable.COLUMN_OPTION1 + " TEXT," +
            questiontable.COLUMN_OPTION2 + " TEXT," +
            questiontable.COLUMN_OPTION3 + " TEXT," +
            questiontable.COLUMN_OPTION4 + " TEXT," +
            questiontable.COLUMN_ANSWER_NR + "INTEGER" +
            ")";
    db.execSQL(SQL_CREATE_QUESTIONS_TABLE);
    fillquestionstable();
}'''

这是日志猫:

Process: com.example.modaltest, PID: 6534
java.lang.RuntimeException: Unable to startactivityComponentInfo{com.example.modaltest/com.example.modaltest.quiz}:android.database.sqlite.SQLiteException: near ".": syntax error (code 1): , while compiling: CREATE TABLE quiz_questions ( _id INTEGER PRIMARY KEY AUTOINCREMENT,com.example.modaltest.questionTEXT,option1 TEXT,option2 TEXT,option3 TEXT,option4 TEXT,answer_nrINTEGER)
    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:866)at 
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
4

5 回答 5

1

你必须改变这条线

questiontable.COLUMN_QUESTION + "TEXT,"+ 到questiontable.COLUMN_QUESTION + " TEXT,"+

之前的空间TEXT

于 2020-03-11T13:27:50.313 回答
0

查询中有 3 个错误。

首先是您在questiontable.COLUMN_QUESTION提供的列名中使用了。在您的示例中,您似乎使用“ com.example.modaltest.question ”作为列名,这是行不通的。

  1. 列名称只允许使用字母数字字符和下划线。
  2. 列名必须始终以字母字符或下划线开头。

因此,您需要将“com.example.modaltest.question”替换为没有任何点的正确列名。

其他两个错误与空格有关。在接下来的声明中,您需要在列名和列类型之间包含一个空格,就像您对其他列声明所做的那样:

questiontable.COLUMN_QUESTION + "TEXT,"

questiontable.COLUMN_ANSWER_NR + "INTEGER"

应该是"TEXT""INTEGER",注意每个字符串开头的空格。"

于 2020-03-11T13:34:10.837 回答
0

您的查询中有两个错误。

1.第一行questiontable.COLUMN_QUESTION + "TEXT," +

将是(在TEXT之前给空间)

questiontable.COLUMN_QUESTION + " TEXT," +

2.最后一行questiontable.COLUMN_ANSWER_NR + "INTEGER" +

将是(在INTEGER之前给空间)

questiontable.COLUMN_ANSWER_NR + " INTEGER" +

谢谢你。

于 2020-03-11T13:35:49.870 回答
0
  questiontable.COLUMN_QUESTION + " TEXT," +

问题是在您的行中, questiontable.COLUMN_QUESTION 和 TEXT 之间没有距离,因此它们合并为一行,从而导致错误

于 2020-03-11T13:30:27.540 回答
0

你在查询中有错误检查这个

final String SQL_CREATE_QUESTIONS_TABLE =
        "CREATE TABLE " +
        questiontable.TABLE_NAME + " ( " +
        questiontable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
        questiontable.COLUMN_QUESTION + " TEXT," +
        questiontable.COLUMN_OPTION1 + " TEXT," +
        questiontable.COLUMN_OPTION2 + " TEXT," +
        questiontable.COLUMN_OPTION3 + " TEXT," +
        questiontable.COLUMN_OPTION4 + " TEXT," +
        questiontable.COLUMN_ANSWER_NR + "INTEGER" +
        ")";
于 2020-03-11T13:24:30.833 回答