前提・実現したいこと
現在,「はじめてのAndroidプログラミング」という参考書でJavaの勉強をしております。
その参考書でスケジュールアプリを作成して、いろいろと学んでいるのですが、エミュレーターでアプリを起動瞬間に強制終了するので、これを治したいです。
どなたかよろしくお願いいたします。
発生している問題・エラーメッセージ
実行したときのログになります。
ログの中にものすごい長い文があり、この文の中に、**Unsupported Realm file format version. (Unsupported Realm file format version) **
があると思うんですが、これが原因かなと思っております。
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myscheduler, PID: 31814 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myscheduler/com.example.myscheduler.MainActivity}: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.example.myscheduler/files/default.realm': Unsupported Realm file format version. (Unsupported Realm file format version) (/data/data/com.example.myscheduler/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109 Kind: ACCESS_ERROR. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: io.realm.exceptions.RealmFileException: Unable to open a realm at path '/data/data/com.example.myscheduler/files/default.realm': Unsupported Realm file format version. (Unsupported Realm file format version) (/data/data/com.example.myscheduler/files/default.realm) in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 109 Kind: ACCESS_ERROR. at io.realm.internal.SharedRealm.nativeGetSharedRealm(Native Method) at io.realm.internal.SharedRealm.<init>(SharedRealm.java:187) at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:229) at io.realm.internal.SharedRealm.getInstance(SharedRealm.java:204) at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:124) at io.realm.Realm.getDefaultInstance(Realm.java:210) at com.example.myscheduler.MainActivity.onCreate(MainActivity.java:36) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
該当のソースコード
MainActivity.java
java
1package com.example.myscheduler; 2 3import android.content.Intent; 4import android.os.Bundle; 5import android.view.View; 6import android.widget.ListView; 7 8import androidx.appcompat.app.AppCompatActivity; 9import androidx.appcompat.widget.Toolbar; 10 11import com.google.android.material.floatingactionbutton.FloatingActionButton; 12 13import io.realm.Realm; 14import io.realm.RealmResults; 15 16public class MainActivity extends AppCompatActivity { 17 18 private Realm mRealm; 19 private ListView mListView; 20 21 @Override 22 protected void onCreate(Bundle savedInstanceState) { 23 super.onCreate(savedInstanceState); 24 setContentView(R.layout.activity_main); 25 Toolbar toolbar = findViewById(R.id.toolbar); 26 setSupportActionBar(toolbar); 27 28 FloatingActionButton fab = findViewById(R.id.fab); 29 fab.setOnClickListener(new View.OnClickListener() { 30 @Override 31 public void onClick(View view) { 32 startActivity( new Intent(MainActivity.this,ScheduleEditActivity.class)); 33 } 34 }); 35 36 mRealm = Realm.getDefaultInstance(); 37 38 mListView = (ListView)findViewById(R.id.listView); 39 40 RealmResults<Schedule> schedules = mRealm.where(Schedule.class).findAll(); 41 ScheduleAdapter adapter = new ScheduleAdapter(schedules); 42 mListView.setAdapter(adapter); 43 } 44 45 @Override 46 public void onDestroy() { 47 super.onDestroy(); 48 mRealm.close(); 49 } 50}
build.gradle(Module:MyScheduler.app)
apply plugin: 'com.android.application' apply plugin: 'realm-android' android { compileSdkVersion 29 buildToolsVersion "30.0.2" defaultConfig { applicationId "com.example.myscheduler" minSdkVersion 23 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.navigation:navigation-fragment:2.3.3' implementation 'androidx.navigation:navigation-ui:2.3.3' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' compile 'io.realm:android-adapters:2.0.0' }
build.gradle(Project:MyScheduler)
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath "com.android.tools.build:gradle:4.1.2" classpath "io.realm:realm-gradle-plugin:3.0.0" } } allprojects { repositories { google() jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }
試したこと
参考書通りに進めているため、何がダメなのかわからないので、何も出来ておりません。
補足情報(FW/ツールのバージョンなど)
Android Studio: 4.1.2
回答1件
あなたの回答
tips
プレビュー