There seems to be some context issue in the next line when I get a NullPointerException . I think something is wrong with the context. Also, when I try to open and close a database of two actions, it throws a CannotOpenORCloseDatabase Error. Please, help.
DBHelper dbHelper = new DBHelper(this.getApplicationContext());
Any idea why? Or it would be great if someone could offer a workaround.
public static final String EXT_CATEGORY = "category"; public static final String EXT_URL = "url"; private String tableName = DBHelper.tableName; private SQLiteDatabase MyDb; private int category; Cursor c = null; public static final String EXT_POS = "position"; private String url; private int position; WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { Log.v(LOG_TAG, "onCreate() called"); super.onCreate(savedInstanceState); openAndQueryDatabase(); } private void openAndQueryDatabase() { position = 1; category = 0; Log.v(LOG_TAG, "onCreate() called 3"); try { DBHelper dbHelper = DBHelper.getInstance(getBaseContext()); MyDb = dbHelper.getWritableDatabase(); c = MyDb.rawQuery("SELECT * FROM " + tableName + " where Category =" + category + "AND Position =" + position, null); Log.v(LOG_TAG, "onCreate() called 4");
source share