デバッグなう

This commit is contained in:
nemukemo 2024-06-28 12:40:00 +09:00
parent b29545dc0d
commit 0c569b0a57
3 changed files with 9 additions and 8 deletions

View File

@ -3,7 +3,7 @@ package com.example.oplogy;
import androidx.room.Database;
import androidx.room.RoomDatabase;
@Database(entities = {SetUpTable.class}, version = 2, exportSchema = false)
@Database(entities = {SetUpTable.class}, version = 3, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase {
// データベースにアクセスするためのメソッドを提供する
public abstract SetUpTableDao setUpTableDao();

View File

@ -176,7 +176,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// タスク1: ローカルDBから生徒数を取得してtotalStudentと比較
executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable")
.fallbackToDestructiveMigration()
.build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
Log.d("MainActivity", "db" + setUpTableDao.getAll());
@ -341,7 +343,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//roomからclassIdを取得
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build();
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable")
.fallbackToDestructiveMigration()
.build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
classId = setUpTableDao.getClassId();
});

View File

@ -127,11 +127,8 @@ public class SetUpActivity extends FragmentActivity
executor.execute(() -> {
//roomのインスタンスを作成
AppDatabase db = Room.databaseBuilder(
getApplicationContext(),
AppDatabase.class,
"SetUpTable"
)
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable")
.fallbackToDestructiveMigration()
.build();
SetUpTableDao setUpTableDao = db.setUpTableDao();
// Roomの操作を行う