delay to connect database sqlite android -


i've sqlite file use app , follow tutorial using sqlite file : link tutorial

in database i've many coordinates , every coordinates, mark on fragment map of activity. when start application on device (acer e330) give me error:

07-11 16:47:15.928: e/androidruntime(11095): fatal exception: main 07-11 16:47:15.928: e/androidruntime(11095): java.lang.runtimeexception: unable start activity componentinfo{com.frank.nuova/com.frank.nuova.offline}: android.database.sqlite.sqliteexception: no such table: linee: , while compiling: select lat, long, via linee 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activitythread.performlaunchactivity(activitythread.java:1956) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:1981) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activitythread.access$600(activitythread.java:123) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activitythread$h.handlemessage(activitythread.java:1147) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.os.handler.dispatchmessage(handler.java:99) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.os.looper.loop(looper.java:137) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activitythread.main(activitythread.java:4424) 07-11 16:47:15.928: e/androidruntime(11095):    @ java.lang.reflect.method.invokenative(native method) 07-11 16:47:15.928: e/androidruntime(11095):    @ java.lang.reflect.method.invoke(method.java:511) 07-11 16:47:15.928: e/androidruntime(11095):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:787) 07-11 16:47:15.928: e/androidruntime(11095):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:554) 07-11 16:47:15.928: e/androidruntime(11095):    @ dalvik.system.nativestart.main(native method) 07-11 16:47:15.928: e/androidruntime(11095): caused by: android.database.sqlite.sqliteexception: no such table: linee: , while compiling: select lat, long, via linee 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitecompiledsql.native_compile(native method) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitecompiledsql.<init>(sqlitecompiledsql.java:68) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqliteprogram.compilesql(sqliteprogram.java:143) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqliteprogram.compileandbindallargs(sqliteprogram.java:361) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:127) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:94) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitequery.<init>(sqlitequery.java:53) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitedirectcursordriver.query(sqlitedirectcursordriver.java:47) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitedatabase.rawquerywithfactory(sqlitedatabase.java:1564) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitedatabase.querywithfactory(sqlitedatabase.java:1449) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitedatabase.query(sqlitedatabase.java:1405) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.database.sqlite.sqlitedatabase.query(sqlitedatabase.java:1485) 07-11 16:47:15.928: e/androidruntime(11095):    @ com.frank.nuova.datasource.vedicoordinate(datasource.java:21) 07-11 16:47:15.928: e/androidruntime(11095):    @ com.frank.nuova.offline.oncreate(offline.java:40) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activity.performcreate(activity.java:4465) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) 07-11 16:47:15.928: e/androidruntime(11095):    @ android.app.activitythread.performlaunchactivity(activitythread.java:1920) 07-11 16:47:15.928: e/androidruntime(11095):    ... 11 more 

but after while (10 seconds) works, make visible marks on map right coordinates of database. same code connect database of app i'm trying use spinner in list coordinates of db. app crash same error of app before. i've thought problem of delay connect on database possible?

this activity:

public class offline extends activity { myopenhelper o; datasource db; latlng pos;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_offline);     o=new myopenhelper(this);     try{         o.createdatabase();     }catch (ioexception e){         throw new error("non posso creare il database");     }     try{         o.opendatabase();     }catch(sqlexception sql){         sql.printstacktrace();     }     db=new datasource(o);     listview l=(listview)findviewbyid(r.id.listview1);     gps s=new gps(getapplicationcontext());     location adesso=s.getlocation();     list<latlng> vicini=db.piuvicino(adesso, db.vedicoordinate());     arrayadapter<latlng> a=new arrayadapter<latlng>(getapplicationcontext(),android.r.layout.simple_list_item_1,vicini);     l.setadapter(a);  }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.offline, menu);     return true; }       } 

this myopenhelper.java

public class myopenhelper extends sqliteopenhelper{      //the android's default system path of application database.     private static string db_path = "";      private static string db_name = "orari";      private sqlitedatabase mydatabase;       private final context mycontext;      /**      * constructor      * takes , keeps reference of passed context in order access application assets , resources.      * @param context      */     public myopenhelper(context context) {         super(context, db_name, null, 1);// 1? database version         if(android.os.build.version.sdk_int >= 4.2){             db_path = context.getapplicationinfo().datadir + "/databases/";                  } else {            db_path = "/data/data/" + context.getpackagename() + "/databases/";         }         this.mycontext = context;      }       /**      * creates empty database on system , rewrites own database.      * */     public void createdatabase() throws ioexception{          boolean dbexist = checkdatabase();          if(dbexist){             //do nothing - database exist         }else{              //by calling method , empty database created default system path                //of application gonna able overwrite database our database.             this.getreadabledatabase();              try {                  copydatabase();               } catch (ioexception e) {                  throw new error("error copying database");              }         }      }      /**      * check if database exist avoid re-copying file each time open application.      * @return true if exists, false if doesn't      */     private boolean checkdatabase(){          sqlitedatabase checkdb = null;          try{             string mypath = db_path + db_name;             checkdb = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readwrite);          }catch(sqliteexception e){              //database does't exist yet.          }          if(checkdb != null){              checkdb.close();          }          return checkdb != null ? true : false;     }      /**      * copies database local assets-folder created empty database in      * system folder, can accessed , handled.      * done transfering bytestream.      * */     private void copydatabase() throws ioexception{          //open local db input stream         inputstream myinput = mycontext.getassets().open(db_name);          // path created empty db         string outfilename = db_path + db_name;          //open empty db output stream         outputstream myoutput = new fileoutputstream(outfilename);          //transfer bytes inputfile outputfile         byte[] buffer = new byte[1024];         int length;         while ((length = myinput.read(buffer))>0){             myoutput.write(buffer, 0, length);         }          //close streams         myoutput.flush();         myoutput.close();         myinput.close();      }      public void opendatabase() throws sqlexception{          //open database         string mypath = db_path + db_name;         mydatabase = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readwrite);       }      @override     public synchronized void close() {              if(mydatabase != null)                 mydatabase.close();              super.close();      }     @override     public void oncreate(sqlitedatabase db) {         // todo auto-generated method stub      }      @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {         // todo auto-generated method stub      }          // add public helper methods access , content database.        // return cursors doing "return mydatabase.query(....)" it'd easy        // create adapters views.  } 

and datasource.java

public class datasource { private myopenhelper oh; private cursor cu; public datasource(myopenhelper o){     oh=o; } public list<coordinate> vedicoordinate(){     sqlitedatabase db=oh.getreadabledatabase();     string c[]=new string[]{"lat","long","via"};     cu=db.query("linee", c, null, null, null, null, null);     int rows=cu.getcount();     linkedlist<coordinate> risultato=new linkedlist<coordinate>();     cu.movetofirst();     for(int i=0;i<rows;i++){         risultato.add(i,new coordinate(cu.getdouble(cu.getcolumnindex("lat")),cu.getdouble(cu.getcolumnindex("long")),cu.getstring(cu.getcolumnindex("via"))));         cu.movetonext();     }     cu.close();     return risultato;    } public double distanza(location l,latlng m){     double startlat=l.getlatitude();     double startlon=l.getlongitude();     double endlat=l.getlatitude();     double endlon=l.getlongitude();     float[]res=new float[1];     location.distancebetween(startlat, startlon, endlat, endlon, res);     return res[0]; } public list<latlng> piuvicino(location l,list<coordinate> a){     latlng b;     double dist=0;     linkedlist <latlng> lista=new linkedlist<latlng>();     for(int i=0;i<a.size();i++){         b=new latlng(a.get(i).getlatitudine(), a.get(i).getlongitudine());         dist=distanza(l,b);         if (dist<0.5){             lista.add(new latlng(a.get(i).getlatitudine(), a.get(i).getlongitudine()));         }     }     return lista; }     } 


Comments