Well try to create all your tables in the onCreate method of class that subclasses SQLiteOpenHelper. Then when you call db.getWriteableDatabase(), if the database is not created, the onCreate() method gets called for you and then well you do not need to worry about a null database.
On Jun 25, 3:37 pm, Ramsey Statz <[email protected]> wrote: > So here's the basic idea of my code. Each activity that needs access > to the database has its own instance of the DataHelper class. I do > that with this statement: > > final DataHelper dataHelper = new DataHelper(this); > > The DataHelper constructor looks like this: > > public DataHelper(Context _context) > { > context = _context; > dbHelper = new DBHelper(context); // dbHelper is an variable > created outside of the constructor. DBHelper is a static class > created within the DataHelper class as a subclass of SQLiteOpenHelper. > } > > The DataHelper class has necessary instance variables such as an > SQLiteDatabase (db) and a DBHelper (dbHelper. > > Then, in each activity that uses the database, I use the onResume() > and onPause methods. The onResume() method has the following > statement: > > dataHelper.open(); > > and here's the method for open() as declared in the DataHelper class. > > public DataHelper open() throws SQLException > { > db = dbHelper.getWritableDatabase(); > return this; > } > > and then I do this in the onPause() method: > > dataHelper.close(); > > public void close() > { > db.close(); > } > > That's about all I've got. Hope it helps you help me. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

