• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps SqLite table not found

mist3r0

Newbie
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:
   public MyDbHelper(Context ctx) {

         private SQLiteDatabase db;

         try {
                db = ctx.openOrCreateDatabase("myDB.db", 0, null);
            } catch (SQLiteException e) {
                
                    db = ctx.openOrCreateDatabase("NewMyDB.db", 0, null);
                    
                    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");

                    db.close();
          }

:confused::confused::confused::confused::confused::confused::confused::confused::confused:
 
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.
 
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! :confused:

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.
 
Back
Top Bottom