Home > Net >  Android sqlite nullpointerexception when inputting data
Android sqlite nullpointerexception when inputting data

Time:02-10

Hi im fairly new to android studio and I keep getting

this error NullPointerException when inserting data to database

The method

 void displayData() {
    Cursor cursor = sh.readAllData();

    if(cursor.getCount() == 0) {
        Toast.makeText(Scores.this, "No scores", Toast.LENGTH_SHORT).show();
    } else {
        while(cursor.moveToNext()) {
             studentName.add(cursor.getString(0));
             score.add(cursor.getInt(0));
             genre.add(cursor.getString(0));
        }
    }
}

My database method

Cursor readAllData(){
    String query = "SELECT * FROM "   "scores";
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = null;

    if(db != null) {
        cursor = db.rawQuery(query,null);
    }

    return cursor;

}

CodePudding user response:

  •  Tags:  
  • Related