在Android上创建JAXBContext会引发ClassCastException

时间:2018-08-10 21:20:54

标签: android jaxb

晚上好

我已经使用JAXB(javax.xml.bind:jaxb-api:2.1)编写了一个Java库,该库在我的桌面应用程序中正常工作。

现在,我想在android上使用此库,但是当我尝试创建JAXBContext时:

JAXBContext context =
    JAXBContext.newInstance(ObjectFactory.class.getPackage().getName(),
    this.getClass().getClassLoader());

我收到此错误(请参见下面的stacktrace)。

我很高兴能向我推荐任何方向的提示。 在此先感谢!

Stacktrace:

W/System.err: java.util.MissingResourceException: Can't find bundle for base name javax.xml.bind.Messages, locale de_DE
W/System.err:     at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1501)
                  at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1324)
                  at java.util.ResourceBundle.getBundle(ResourceBundle.java:723)
                  at javax.xml.bind.Messages.format(Messages.java:71)
                  at javax.xml.bind.Messages.format(Messages.java:56)
                  at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148)
                  at javax.xml.bind.ContextFinder.find(ContextFinder.java:371)
                  at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446)
W/System.err:     at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409)
                  at org.foo.mylibraryapi.persistence.adapter.ModelReader.readDocument(ModelReader.java:67)
                  at org.foo.mylibraryapi.persistence.adapter.ModelReader.readDocument(ModelReader.java:30)
                  at org.foo.mylibrary.ui.FileLoader.load(FileLoader.java:14)
                  at org.foo.ambitusapp.MainActivity.onActivityResult(MainActivity.java:180)
                  at android.app.Activity.dispatchActivityResult(Activity.java:6946)
                  at android.app.ActivityThread.deliverResults(ActivityThread.java:4126)
                  at android.app.ActivityThread.handleSendResult(ActivityThread.java:4173)
                  at android.app.ActivityThread.-wrap20(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:154)
                  at android.app.ActivityThread.main(ActivityThread.java:6165)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
W/System.err: Caused by: java.lang.ClassCastException: javax.xml.bind.Messages cannot be cast to ResourceBundle
                  at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2576)
                  at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1438)
                  at java.util.ResourceBundle.findBundle(ResourceBundle.java:1402)
                  at java.util.ResourceBundle.findBundle(ResourceBundle.java:1356)
                  at java.util.ResourceBundle.findBundle(ResourceBundle.java:1356)
                  at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1298)
                ... 22 more

0 个答案:

没有答案