This question already has an answer here:
I'm trying to receive information from a sqlite database in a class called userLogin (it's just for testing). The database and table already exists. This is my code:
public class userLogin {
protected SQLiteDatabase db;
protected Cursor c;
protected static final String SELECT_SQL = "SELECT email,password FROM userInformation";
public String email;
Public String password;
public void userLogin()
{
setValues();
}
public void setValues() {
//database values
c = db.rawQuery(SELECT_SQL, null);
if ((c.moveToFirst()) || !(c.getCount() == 0)) {
c.moveToFirst();
this.email = c.getString(0);
this.password = c.getString(1);
}
else {
this.email = "empty";
this.password = "empty";
}
}
public String String()
{
return this.email;
}
}
I call the class like this:
userLogin checkLogin = new userLogin();
Toast.makeText(Login.this, checkLogin.test(), Toast.LENGTH_SHORT).show();
When I do this I receive the error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.rawQuery(java.lang.String, java.lang.String[])' on a null object reference
Aucun commentaire:
Enregistrer un commentaire