I created a DBTest SQLiteOpenHelper class
Then I called it from my main interface.
It crashes when I hit DB.GetReadableDatabase () and the log doesn't help, it just says a null pointer, but I don't know where to look.
Everything works if I use
SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
Same database
Here is a class for helper and below error:
public class DBTest extends SQLiteOpenHelper { private static String DB_NAME = "DB"; private SQLiteDatabase myDataBase; private final Context myContext; public DBTest(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } @Override public void onCreate(SQLiteDatabase db) {
The following is the error:
public class Main extends Activity { DataBaseHelper db = new DataBaseHelper(null); static SQLiteDatabase Db; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SQLiteDatabase Db; DBTest db1 = new DBTest(null); Db = db1.getReadableDatabase(); <<< blow up here } }
source share