I've migrated my old app to use the new Room database implementation (wow it took forever even though it's got 5 small, simple tables) but now for some reason when I launch the app it crashes immediately. It's especially nice because Logcat doesn't show a thing, because it appears it needs the app actually running to show anything (you have to select the process in that dropdown).
It's just this line in my Fragment class:
private ShotTrackerDao dao = ShotTrackerRoomDatabase.getDatabase(getContext()).shotTrackerDao();
If I comment it out, it runs fine. The Room DB class and the DAO class are the same as in the Udemy course I'm following and in YouTube videos I see on the topic.
@Dao
public interface ShotTrackerDao {
@Insert(onConflict = OnConflictStrategy.ABORT)
void insertFirearm(Firearm firearm);
@Query("UPDATE firearm SET deleted = '1'")
void deleteAllFirearms();
... so on, so forth
}
And the Room DB:
@Database(entities = { Ammunition.class, Caliber.class, Firearm.class, ShotTrack.class, UnitOfMeasure.class },
version = 2,
exportSchema = true)
@TypeConverters({CustomTypeConverters.class})
public abstract class ShotTrackerRoomDatabase extends RoomDatabase {
private static volatile ShotTrackerRoomDatabase INSTANCE;
private static final String DATABASE_NAME = "shot_tracker.db";
private static final int NUMBER_OF_THREADS = 4;
public abstract ShotTrackerDao shotTrackerDao();
public static final ExecutorService databaseWriteExecutor = Executors.newFixedThreadPool(NUMBER_OF_THREADS);
public static ShotTrackerRoomDatabase getDatabase(final Context context)
{
if (INSTANCE == null) {
synchronized (ShotTrackerRoomDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), ShotTrackerRoomDatabase.class, DATABASE_NAME)
.addMigrations(MIGRATION_1_2)
.build();
}
}
}
return INSTANCE;
}
... also has a Migration in it, although that's already worked
}
Does anyone know how I can figure out what's going wrong? I have no idea with Logcat not doing anything. Thanks much for any help.