Androidアプリの作成にRealmを
使用しているがバージョンアップで
エラーが発生したので
その対処法を記録。
今までAndroidアプリの開発で
使用していたrealmのプラグインはver6.0.1であったが、
新たなアプリ開発でver10.4.0に
したところエラーが発生。
エラーの内容としては
io.realm.exceptions.RealmException: Running transactions on the UI thread has been disabled.
It can be enabled by setting 'RealmConfiguration.Builder.allowWritesOnUiThread(true)'.
と表示される。
エラー個所はonCreate内の.executeTransactionが指されている。
原因はUIスレッドでのTransactionが
使用不可となっており、
対策はエラーメッセージに書いてあるようにRealmConfiguration.Builderで
allowWritesOnUiThread(true)を
セッティングする必要がある。
対策
RealmConfiguration realmConfig;
realmConfig = new RealmConfiguration.Builder().name("******").allowWritesOnUiThread(true).build();
<前の記事
次の記事>