How to use MongoDB Morphia on Android?

爷,独闯天下 提交于 2019-12-25 02:19:13

问题


I am trying to use morphia on an Android application to interact with a MongoDB instance.

Gradle dependency: implementation 'org.mongodb.morphia:morphia:1.3.2'

When instantiating Morphia Morphia morphia = new Morphia();

I get this error:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.dibu2018.futbol, PID: 5085
                  java.lang.ExceptionInInitializerError
                      at java.lang.Class.classForName(Native Method)
                      at java.lang.Class.forName(Class.java:453)
                      at java.lang.Class.forName(Class.java:378)
                      at org.mongodb.morphia.mapping.lazy.LazyFeatureDependencies.testDependencyFullFilled(LazyFeatureDependencies.java:42)
                      at org.mongodb.morphia.mapping.lazy.LazyFeatureDependencies.createDefaultProxyFactory(LazyFeatureDependencies.java:57)
                      at org.mongodb.morphia.mapping.Mapper.<init>(Mapper.java:102)
                      at org.mongodb.morphia.Morphia.<init>(Morphia.java:47)
                      at com.example.dibu2018.futbol.storage.external.datahandlers.FutbolDbHelper.<init>(FutbolDbHelper.java:49)
                      at com.example.dibu2018.futbol.storage.external.datahandlers.FutbolDbHelper.getInstance(FutbolDbHelper.java:27)
                      at com.example.dibu2018.futbol.activities.GameDetailsActivity.onCreate(GameDetailsActivity.java:31)
                      ..........
                   Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
                      at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
                      at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
                      at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
                      ...........
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
                   Caused by: java.lang.reflect.InvocationTargetException
                      at java.lang.reflect.Method.invoke(Native Method)
                      at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
                      at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
                      ............
                   Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
                      at java.lang.ClassLoader.defineClass(ClassLoader.java:591)
                      at java.lang.reflect.Method.invoke(Native Method) 
                      ............

回答1:


As per this github issue Morphia was not built to run on Android. I am assuming my error is due to the attempt to

proxying lazy references

as pointed out by evanchooly on that github issue. The exact error line thrown by AndroidRuntime:

org.mongodb.morphia.mapping.lazy.LazyFeatureDependencies.testDependencyFullFilled(LazyFeatureDependencies.java:42)


来源:https://stackoverflow.com/questions/51604201/how-to-use-mongodb-morphia-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!