1. Are you ready for the Galaxy S20? Here is everything we know so far!

SqLite table not found

Discussion in 'Android Development' started by mist3r0, Dec 28, 2009.

  1. mist3r0

    mist3r0 Newbie
    Thread Starter

    Hello boys,

    I've a problem with my application, when I try to connect at DB, this error occur: (Table "prova" not found)

    this is the code for Read to the db:

    Code (Text):
    3.    public MyDbHelper(Context ctx) {
    5.          private SQLiteDatabase db;
    7.          try {
    8.                 db = ctx.openOrCreateDatabase("myDB.db", 0, null);
    9.             } catch (SQLiteException e) {
    11.                     db = ctx.openOrCreateDatabase("NewMyDB.db", 0, null);
    13.                     db.execSQL("create table prova(_id integer primary key autoincrement)"+"name varchar not null " + "nome2 boolean not null "+"name3 boolean not null "+"name4 boolean not null "+"name5 boolean not null");
    15.                     db.close();
    16.           }

  2. lekky

    lekky Lover

    The code in the catch block is only ran when the first statement fails. If it doesn't fail then the catch code isnt run. That means the table prova is never created.

    So what line does that exception occur at? Is is thrown from that code you show or further down when that table is attempting to be accessed?

    It is bad to put code like that in a catch block, catch blocks should only be used to handle an exception, not for logical code.

    Also the db.close(); should be moved outside of that catch block.
  3. mist3r0

    mist3r0 Newbie
    Thread Starter

    Thanks, but I've write the code in this mode because I've thinks taht:

    if in the block "try" the DB isn't found or there are problem to read, in the block "catch" I try to create a DB.

    The problem is strange because I've create a table "prova" with a SqLite grafic tool, there's also an elemente into the DB, Eclipse return me "error table non found" when I try to read a DB, but if I test the DB with grafical tool, the queys are OK! :thinking:

    Can you send me the correct code for read the DB?

    The DB must be put in place specific of Package Space? I've insert it in the root of the package.

Share This Page