我收到一個關於我的方法的錯誤,允許類訪問我的數據庫。錯誤發生在.getReadableDatabase()。收到的錯誤如下。不知道如何解決這個錯誤。無法對靜態方法進行靜態引用
Cannot make a static reference to the non-static method getReadableDatabase() from the type SQLiteOpenHelper
方法:
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;
用來調用這個方法:
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();
}
}