Skip to content Skip to sidebar Skip to footer

Room Dao Null Pointer Exception

I am getting null pointer exception on the abstract Dao method which we create in room database class. While few sample projects i referred does the same thing but its working. I d

Solution 1:

getInstance() always return null due to wrong test:

public static AppDatabase getInstance(Context context){
    if(appDatabase!=null){ // <= ERROR HERE, should be == null
        appDatabase = Room.databaseBuilder(context.getApplicationContext(),
                AppDatabase.class, "database-name").build();
    }
    return appDatabase;

}

Post a Comment for "Room Dao Null Pointer Exception"