gpt4 book ai didi

java - Android - Realm 异常 : Could Not Find RealmJsonImpl, 未找到类异常

转载 作者:太空宇宙 更新时间:2023-11-04 13:50:40 25 4
gpt4 key购买 nike

这是我的 Realm 对象:

public class StringThisClassRealm extends RealmObject {
String string = "";

public String getString() {
return string;
}

public void setString(String string) {
this.string = string;
}
}

我将此称为我的 Activity 的 onCreate 来测试目的:

Realm realm = Realm.getInstance(this);
realm.beginTransaction();
StringThisClassRealm cr = realm.createObject(StringThisClassRealm.class);
cr.setString("String");
realm.commitTransaction();

当我调试时,它从未经过第一行Realmrealm = Realm.getInstance(this);

应用程序崩溃,这是我的日志跟踪:

05-19 13:15:44.440: E/AndroidRuntime(12300): FATAL EXCEPTION: main 
05-19 13:15:44.440: E/AndroidRuntime(12300): Process: uk.org.humanfocus.hfi, PID: 12300
05-19 13:15:44.440: E/AndroidRuntime(12300): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.org.humanfocus.hfi/uk.org.humanfocus.hfi.sclr.CompetencyAssessment}: io.realm.exceptions.RealmException: Could not find io.realm.RealmJsonImpl
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.ActivityThread.access$800(ActivityThread.java:144)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.os.Handler.dispatchMessage(Handler.java:102)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.os.Looper.loop(Looper.java:212)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.ActivityThread.main(ActivityThread.java:5135)
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 13:15:44.440: E/AndroidRuntime(12300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
05-19 13:15:44.440: E/AndroidRuntime(12300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
05-19 13:15:44.440: E/AndroidRuntime(12300): at dalvik.system.NativeStart.main(Native Method)
05-19 13:15:44.440: E/AndroidRuntime(12300): Caused by: io.realm.exceptions.RealmException: Could not find io.realm.RealmJsonImpl
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.getRealmJson(Realm.java:268)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.<init>(Realm.java:165)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.createAndValidate(Realm.java:513)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.create(Realm.java:486)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.getInstance(Realm.java:404)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.getInstance(Realm.java:366)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.getInstance(Realm.java:347)
05-19 13:15:44.440: E/AndroidRuntime(12300): at uk.org.humanfocus.hfi.sclr.CompetencyAssessment.onCreate(CompetencyAssessment.java:125)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.Activity.performCreate(Activity.java:5231)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-19 13:15:44.440: E/AndroidRuntime(12300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
05-19 13:15:44.440: E/AndroidRuntime(12300): ... 11 more
05-19 13:15:44.440: E/AndroidRuntime(12300): Caused by: java.lang.ClassNotFoundException: io.realm.RealmJsonImpl
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.Class.classForName(Native Method)
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.Class.forName(Class.java:251)
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.Class.forName(Class.java:216)
05-19 13:15:44.440: E/AndroidRuntime(12300): at io.realm.Realm.getRealmJson(Realm.java:263)
05-19 13:15:44.440: E/AndroidRuntime(12300): ... 21 more
05-19 13:15:44.440: E/AndroidRuntime(12300): Caused by: java.lang.NoClassDefFoundError: io/realm/RealmJsonImpl
05-19 13:15:44.440: E/AndroidRuntime(12300): ... 25 more
05-19 13:15:44.440: E/AndroidRuntime(12300): Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.RealmJsonImpl" on path: DexPathList[[zip file "/data/app/uk.org.humanfocus.hfi-2.apk"],nativeLibraryDirectories=[/data/app-lib/uk.org.humanfocus.hfi-2, /vendor/lib, /system/lib]]
05-19 13:15:44.440: E/AndroidRuntime(12300): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
05-19 13:15:44.440: E/AndroidRuntime(12300): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)

在这里您可以看到工厂路径:

enter image description here

最佳答案

您需要添加@RealmClass注释来触发注释预处理器,从而启动/触发注释过程。它本身也将包含引用。休息就好

关于java - Android - Realm 异常 : Could Not Find RealmJsonImpl, 未找到类异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30317437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com