Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following execSQL in my android project that is throwing a syntax error and causing my app to crash. I can't figure out why.

private static final String TABLE_QUESTIONS = "question";
private static final String KEY_ID_Q = "id";
private static final String KEY_QUESTION_Q = "question";
private static final String KEY_ANSWER1_Q = "answer1";
private static final String KEY_ANSWER2_Q = "answer2";
private static final String KEY_ANSWER3_Q = "answer3";
private static final String KEY_ANSWER4_Q = "answer4";
private static final String KEY_TYPE_Q = "type_Q";
[... ]


    String CREATE_QUESTIONS_TABLE = "CREATE TABLE " + TABLE_QUESTIONS + "("
            + KEY_ID_Q + " INTEGER PRIMARY KEY,"
            + KEY_QUESTION_Q + " TEXT,"
            + KEY_ANSWER1_Q + " INTEGER,"
            + KEY_ANSWER2_Q + " INTEGER,"
            + KEY_ANSWER3_Q + " INTEGER,"
            + KEY_ANSWER4_Q + " INTEGER,"
            + KEY_TYPE_Q + "INTEGER" + ")";
    db.execSQL(CREATE_QUESTIONS_TABLE);
    db.execSQL("INSERT INTO " + TABLE_QUESTIONS +" (" + KEY_QUESTION_Q + ", " + KEY_ANSWER1_Q + ", " + KEY_ANSWER2_Q+ ", " + KEY_ANSWER3_Q + ", " + KEY_ANSWER4_Q + ", " + KEY_TYPE_Q + ") VALUES (" + QUESTION[a] + ", "+(a*4+1)+", "+(a*4+2)+", "+(a*4+3)+", "+(a*4+4)+", "+q_type+");");

LogCat:

    09-28 21:27:26.629: E/Database(1070): Failure 1 (table question has no column named type_Q) on 0x2c3868 when preparing 'INSERT INTO question (question, answer1, answer2, answer3, answer4, type_Q) VALUES ('AnyString', 1, 2, 3, 4, 1);'.

I hope some of you guys can figure it out :)

share|improve this question

1 Answer 1

It's as simple as that you forgot a space;

+ KEY_TYPE_Q + "INTEGER" + ")";

should be

+ KEY_TYPE_Q + " INTEGER" + ")";

...otherwise you'll try to create a field called type_QINTEGER with no type.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.