I have this method in a class (non-activity) -
public boolean usernameChk(String usrname) {
String usrnmQuery = \"SELECT * FROM \" + TABLE_ACCOUNTS + \"
As your class which is not an Activity this.getReadableDatabase();
is firing NullPointerException as it is not getting context to open database.
Use context to open database. try with following :
DatabaseHandler dbz = new DatabaseHandler(Activity.this);
public Context context;
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// assigning context Change your constructor
this.context = context;
}
// Open database using context object
SQLiteDatabase db = this.getReadableDatabase();