My SQLite give me a null pointer. I am trying to write the points to the database, and to be able to read them from it. That is the complete table. There is nothing else in the table. I am getting the null pointer in the getPoints function, when I run the query. res comes out null.
Here is the code
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(
"create table hour " +
"(id integer primary key, number integer)");
db.execSQL(
"create table points " +
"(id integer primary key, number integer)"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS hour");
onCreate(db);
}
public boolean insertPoints (int points) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("number", points);
db.insert("points", null, contentValues);
return true;
}
public int getPoints() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor res = db.rawQuery( "select number from points where id=1", null );
int i = res.getInt(1);
return i;
}