1

I'm very new to droid development but I was working on some SQL. I have an class which extends the SQLOpenDatabaseHelper and in the onCreate() method I execute this :

        public static final String CREATE_DB = "CREATE TABLE " + TABLE_VOCAB_INFO
        + "(" + COLUMN_NAME + " TEXT NOT NULL PRIMARY KEY," + COLUMN_URL
        + " TEXT NOT NULL," + COLUMN_DOWNLOADED + "TEXT NOT NULL);";

However, when I try to add something to the database like so :

        //Adding method 
        ContentValues cv = new ContentValues();
        cv.put(COLUMN_NAME, "item " + i);
        cv.put(COLUMN_URL, "random url");
        cv.put(COLUMN_DOWNLOADED, "true");
        open();
        database.insert(TABLE_VOCAB_INFO, null, cv);

I get the error:

      (1) no such table: vocab_info

How would I resolve this?

EDIT: more info.

I am creating the database in the onCreate() method of the helper like this:

      public void onCreate(SQLiteDatabase db) {
        try {
            db.execSQL(CREATE_DB);
        } catch (SQLiteException e) {
            System.out.println("Error with creation");
        }
    }

I access the database using the adding method like this

          public void onClick(View viewSelected) {
    switch (viewSelected.getId()) {
    case R.id.bDownload:
        DatabaseManipulator dm = new DatabaseManipulator(this);
        dm.open();
        dm.addList(null);
        dm.addList(null);
        dm.addList(null);
        dm.addList(null);
        dm.addList(null);
        for (VocabList list : dm.getAllLists()) {
            System.out.println(list.getName());
        }
        dm.close();
        break;

Thanks in advance

5
  • Can you show more code? For example how are you reading data from database (because I assume, that this error appears during reading data)? Commented Feb 5, 2013 at 20:51
  • 1
    you will also need to put space between Column name and v type here COLUMN_DOWNLOADED + "TEXT NOT NULL);"; Commented Feb 5, 2013 at 20:53
  • No, the error appears during the code I put in. Commented Feb 5, 2013 at 20:54
  • But why would it not be? Surely an SQLException would be thrown and this is in a try-catch block? Commented Feb 5, 2013 at 20:58
  • 1
    Then show us where are you creating your Database using your CREATE_DB String, and when this putting data part is being executed. Commented Feb 5, 2013 at 20:59

1 Answer 1

1

1) try below create table statement.

 public static final String CREATE_DB = "CREATE TABLE " + TABLE_VOCAB_INFO
        + "(" + COLUMN_NAME + " TEXT NOT NULL PRIMARY KEY," + COLUMN_URL
        + " TEXT NOT NULL," + COLUMN_DOWNLOADED + " TEXT NOT NULL);";

2) If you making any changes to table structure or adding new table, You ll need to uninstall and re-install your application , as onCreate use to call once if there is no DB created, If DB is already there onCreate wont be called and your changes will not gonna affect DB.

Worked for OP >> you can also do this by changing DB version.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm - changing the database version from 1 to 2 seemed to work. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.