SQLite table does not exist exception for existing SQLite database (and table)

Posted by SK9 on Stack Overflow See other posts from Stack Overflow or by SK9
Published on 2011-02-07T02:30:42Z Indexed on 2011/02/07 7:25 UTC
Read the original article Hit count: 534

Filed under:
|

I've followed the instructions given here for introducing an existing SQLite database to your Android app.

When I query the table "android_metadata" this is fine. But when I run a similar query on my own table "words" (which has _id for primary integer key) I get a table does not exist exception and the app crashes.

Why is that?

Code:

Cursor c = myDatabase.query("android_metadata", null, null, null, null, null, null, null);

works but

Cursor c = myDatabase.query("words", null, null, null, null, null, null, null);

returns a table does not exist exception.

This is how I'm creating the database (the references to paths and filenames are correct):

private void copyDatabase() throws IOException{
        //Open local db as the input stream
        InputStream myInput = mContext.getAssets().open(DB_NAME);
        //Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;
        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);
        //Transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }
        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();
    }

(Note: To my eyes, the table is there. I'm looking right at it in my SQLite browser.)

© Stack Overflow or respective owner

Related posts about android

Related posts about sqlite