I am receiving an error on me method to allow a class access to my DB. the error is occurring at .getReadableDatabase(). The error received is below. not sure how to fix this error.
Cannot make a static reference to the non-static method getReadableDatabase() from the type SQLiteOpenHelper
Method:
public static boolean vaidateUser(String username, String password) {
Cursor c = getReadableDatabase().rawQuery(
"SELECT * FROM " + TABLE_NAME_CREDENTIALS + " WHERE "
+ COLUMN_NAME_USERNAME + "='" + username +"'AND "+COLUMN_NAME_PASSWORD+"='"+password+"'" , null);
if (c.getCount()>0)
return true;
return false;
used to call this method:
lsLogin.setOnClickListener (new OnClickListener() {
@Override
public void onClick(View v) {
//check login
String username = lsUsername.getText().toString();
String password = lsPassword.getText().toString();
try{
if(LoginDB.vaidateUser(username,password)) {
Intent goToNextActivity = new Intent(getApplicationContext(), menu.class);
startActivity(goToNextActivity);
Toast.makeText(LoginScrExample.this,"Login Sucessful",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(LoginScrExample.this,"Invalid Username/Password",Toast.LENGTH_LONG).show();
}
}
It means you need an instance of an object to call this method as it is not
staticDo something like:
Cursor c = new YourObject().getReadableDatabase()...Or make the called method also
static