我在我的代码中使用Xstream。下面是初始化部分:
XStream xstream = new XStream(new JettisonMappedXmlDriver()) {
protected MapperWrapper wrapMapper(MapperWrapper next) {
return new MapperWrapper(next) {
@SuppressWarnings("rawtypes")
public boolean shouldSerializeMember(Class definedIn,
String fieldName) {
return definedIn != Object.class ? super
.shouldSerializeMember(definedIn, fieldName)
: false;
}
};
};
};
令人鼓舞的是,当我从一个临时的主方法中调用这个部分时,它很好,但是一旦我运行我的应用程序并且调用了这个代码,我得到一个异常,如下所示:
12-07 19:17:56.374 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.AbstractXMLOutputFactory>
12-07 19:17:56.374 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.AbstractXMLOutputFactory>
12-07 19:17:56.375 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.375 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.388 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.AbstractXMLInputFactory>
12-07 19:17:56.389 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.AbstractXMLInputFactory>
12-07 19:17:56.390 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.391 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.391 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.397 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.397 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.403 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.403 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.405 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.405 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLInputFactory>
12-07 19:17:56.408 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.408 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.410 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.412 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.412 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.414 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.417 8957-8957/com.rsa.mobile.android.transactionsigningsdk I/art: Rejecting re-init on previously-failed class java.lang.Class<org.codehaus.jettison.mapped.MappedXMLOutputFactory>
12-07 19:17:56.417 8957-8957/com.rsa.mobile.android.transactionsigningsdk D/AndroidRuntime: Shutting down VM
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: FATAL EXCEPTION: main
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: Process: com.rsa.mobile.android.transactionsigningsdk, PID: 8957
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: java.lang.NoClassDefFoundError: org.codehaus.jettison.mapped.MappedXMLOutputFactory
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:77)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:63)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:55)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.rsa.mobile.android.transactionsigningsdk.transaction.TransactionPayloadProcessorImpl.processTransactionPayload(TransactionPayloadProcessorImpl.java:20)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.rsa.mobile.android.transactionsigningsdk.MainActivity$2.onClick(MainActivity.java:48)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at android.view.View.performClick(View.java:4786)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:19902)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5290)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
12-07 19:17:56.418 8957-8957/com.rsa.mobile.android.transactionsigningsdk E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
下面是我的build.gradle。可以看出,我在我的libs文件夹中添加了一个jettison jar,因为在xstream类中没有。
apply plugin: 'com.android.application'
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/ksoap2-android-releases/'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
android {
packagingOptions {
exclude 'META-INF/services/org.xmlpull.v1.XmlPullParserFactory'
}
}
defaultConfig {
applicationId "com.rsa.mobile.android.transactionsigningsdk"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile('com.thoughtworks.xstream:xstream:1.4.7') {
exclude module: 'xmlpull'
}
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile ('com.google.code.ksoap2-android:ksoap2-android:3.0.0'){
exclude module: 'xmlpull'
}
compile files ('libs/jettison-1.3.jar')
compile files ('libs/commons-codec-1.7.jar')
}
有人可以帮忙吗。