Android - 领域异常:无法找到 RealmJsonImpl,Class 未找到异常
Android - Realm Exception: Could Not Find RealmJsonImpl, Class Not Found Exception
这是我的领域对象:
public class StringThisClassRealm extends RealmObject {
String string = "";
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
}
我将此称为 Activity 的 onCreate 用于测试 purpsoe:
Realm realm = Realm.getInstance(this);
realm.beginTransaction();
StringThisClassRealm cr = realm.createObject(StringThisClassRealm.class);
cr.setString("String");
realm.commitTransaction();
当我调试的时候,它从来没有经过第一行Realm realm = Realm.getInstance(this);
应用程序崩溃,这是我的 logTrace:
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.access0(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)
这里可以看到工厂路径:
您需要添加 @RealmClass
的注解来触发 initates/triggers annotation process
的注解预处理器。它本身也将包括参考。好好休息
这是我的领域对象:
public class StringThisClassRealm extends RealmObject {
String string = "";
public String getString() {
return string;
}
public void setString(String string) {
this.string = string;
}
}
我将此称为 Activity 的 onCreate 用于测试 purpsoe:
Realm realm = Realm.getInstance(this);
realm.beginTransaction();
StringThisClassRealm cr = realm.createObject(StringThisClassRealm.class);
cr.setString("String");
realm.commitTransaction();
当我调试的时候,它从来没有经过第一行Realm realm = Realm.getInstance(this);
应用程序崩溃,这是我的 logTrace:
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.access0(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)
这里可以看到工厂路径:
您需要添加 @RealmClass
的注解来触发 initates/triggers annotation process
的注解预处理器。它本身也将包括参考。好好休息