Getting above exception while trying to access Realm database.
I tried various method which is suggested in stackoverflow. But nothing solves the problem. I have provided the details please help me resolve the issue. App gets crashed when trying to get User class.
build.gradle(Project:My_project)
allprojects {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven { url "https://jitpack.io" }
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
}
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
build.gradle(Module:app)
plugins {
id "com.android.application"
id "org.jetbrains.kotlin.android"
id "com.google.gms.google-services"
id "com.google.firebase.crashlytics"
}
android {
compileSdkVersion 34
kotlinOptions {
jvmTarget = '17'
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
defaultConfig {
minSdkVersion 23
compileSdkVersion 34
targetSdkVersion 34
multiDexEnabled true
versionCode 20190702
versionName "1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
checkReleaseBuilds false
}
buildTypes {
release {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.1'
implementation("com.google.firebase:firebase-crashlytics-ktx:19.0.3")
implementation("com.google.firebase:firebase-analytics-ktx:22.1.0")
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation "io.realm:realm-android-library:10.15.1"
implementation 'com.github.yukuku:ambilwarna:2.0.1'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'com.facebook.stetho:stetho:1.4.2'
implementation 'com.uphyca:stetho_realm:2.0.0'
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.github.HotBitmapGG:RingProgressBar:V1.2.2'
implementation 'commons-io:commons-io:2.13.0'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'com.google.firebase:firebase-messaging:24.0.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.github.Gavras:MultiLineRadioGroup:v1.0.0.6'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':photoeditorsdk')
implementation project(':videocompression')
}
settings.gradle
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven { url "https://jitpack.io" }
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
}
}
plugins {
id "com.android.application" version "8.3.1" apply false
id "org.jetbrains.kotlin.android" version "1.8.0" apply false
id "com.google.gms.google-services" version "4.4.2" apply false
id "com.google.firebase.crashlytics" version "2.9.9" apply false
}
include ':app', ':photoeditorsdk', ':videocompression'
User class
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;
public class User extends RealmObject {
@PrimaryKey
@SerializedName("userID")
@Expose
private long userId;
public long getUserID() {
return userId;
}
public void setUserID(long userID) {
this.userId = userID;
}
}
Application class onCreate
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.schemaVersion(1)
.migration(new RealmMigrations())
.build();
Realm.setDefaultConfiguration(realmConfiguration);
RealmMigration class
import io.realm.DynamicRealm;
import io.realm.RealmMigration;
import io.realm.RealmSchema;
public class RealmMigrations implements RealmMigration {
@Override
public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
// DynamicRealm exposes an editable schema
RealmSchema schema = realm.getSchema();
/* Migrate to version 1:
Added a new colum in Audit Table .*/
if (oldVersion == 0) {
schema.get("Audit")
.addField("savedAsDraft", boolean.class);
oldVersion++;
}
}
}
7