有一段时间我一直在努力争取这篇文章。我有 不幸的是,我提出了使这篇文章成功的解决方案 在这里结束了这些错误,我一直在努力修复。
当我声明实现 ObjectMapper 时所说的错误。
W/Java7Support: Unable to load JDK7 types (annotations, java.nio.file.Path): no Java7 support added
W/System.err: org.json.JSONException: Value [{"address":"jh...
W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:163)
W/System.err: at org.json.JSONObject.<init>(JSONObject.java:176)
W/System.err: at store.pnp.com.pnp_store.ConfirmOrder.volleyCall(ConfirmOrder.java:250)
W/System.err: at store.pnp.com.pnp_store.ConfirmOrder.access$800(ConfirmOrder.java:50)
W/System.err: at store.pnp.com.pnp_store.ConfirmOrder$3.onClick(ConfirmOrder.java:190)
W/System.err: at android.view.View.performClick(View.java:6256)
W/System.err: at android.view.View$PerformClick.run(View.java:24701)
W/System.err: at android.os.Handler.handleCallback(Handler.java:789)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
W/System.err: at android.os.Looper.loop(Looper.java:164)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6541)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我的学习内容如下:
apply plugin: 'com.android.application'
android {
defaultConfig {
multiDexEnabled true
}
compileSdkVersion 26
defaultConfig {
applicationId "store.pnp.com.pnp_store"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.volley:volley:1.0.0'
implementation files('libs/javax.json-1.0.4.jar')
compile 'com.fasterxml.jackson.core:jackson-core:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.4'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
}
我的Volley使用ObjectMapper将数据转换为json格式 数据,准备保存:
RequestQueue queue = Volley.newRequestQueue(this);
String URL = "http://....108:8080/order/service/save/order";
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
data = new ArrayList<>();
data.add( new CustomerOrder ( email, totalQuantity, cost, phoneNumber, address, closeShop, contact, orderStatus, orderDate, deliveryDate, order ) );
String arrayToJson = objectMapper.writeValueAsString( data );
Log.d( TAG, "Json:" + new JSONObject(arrayToJson));
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, URL, new JSONObject(arrayToJson),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if ( response.length() <= 0 ){
Toast.makeText( getApplicationContext(), "Order Successfully Created...", Toast.LENGTH_SHORT ).show();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// handle error
Log.d(TAG, "Error" + error + "\nmessage" + error.getMessage() );
}
});
我已经搜索了解决方案,尝试了一两个,但它们没有用。一世 还在我的gradle中添加了以下几行:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
如何修复此错误?请帮忙!!!