问题描述
我正在尝试运行以下代码将数据发布到在线 MySQL 数据库
Hi I'm trying to run the below code to post data to a an online MySQL database
if (data.getCount() > 0) {
data.moveToFirst();
do {
save(orderId,client, data.getString(0),data.getString(3),String.valueOf(finalCost),data.getString(4),longitude,latitude,"_",progressDialog);
} while (data.moveToNext());
data.close();
mydb.clearCart();
private void save(final String orderId, final String client, final String prodid, final String Seller, final String amount, final String quantity, final double longi, final double lat, final String location, final ProgressDialog progressDialog) {
String URL_ORDER = "https://foodfuzz.co.ke/foodfuzzbackend/market/orders/order.php";
StringRequest orderStringRequest = new StringRequest(Request.Method.POST, URL_ORDER,
//android M
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject orderObject = new JSONObject(response);
String orderSuccess = orderObject.getString("success");
if(orderSuccess.equals("1")){
pay.setVisibility(View.GONE);
progressDialog.dismiss();
Toast.makeText(CheckOutActivity.this,"Order Placed Successfully " , Toast.LENGTH_SHORT).show();
}else{
Logger.getLogger("Error",orderObject.getString("message"));
pay.setVisibility(View.GONE);
progressDialog.dismiss();
Toast.makeText(CheckOutActivity.this,"Order failed "+orderObject.getString("message") , Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
progressDialog.dismiss();
Toast.makeText(CheckOutActivity.this,"Unable to place order " + e.toString(), Toast.LENGTH_SHORT).show();
pay.setEnabled(true);
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
error.printStackTrace();
Toast.makeText(CheckOutActivity.this,"Error placing order " + error.toString(), Toast.LENGTH_SHORT).show();
pay.setEnabled(true);
}
}){
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("orderId",orderId);
params.put("client", client);
params.put("name", prodid);
params.put("seller", Seller);
params.put("amount", amount);
params.put("quantity",quantity);
params.put("longitude",String.valueOf(longi));
params.put("latitude",String.valueOf(lat));
params.put("location",location);
return params;
}
};
RequestQueue orderRequestQueue = Volley.newRequestQueue(this);
orderRequestQueue.add(orderStringRequest);
}
数据来自可正确检索的 sqlite 数据库.当我在低于 26 的 android 版本上运行它时它可以正常工作,但在高于 26 的版本上我得到以下错误
The data is from an sqlite database wchich is retrieving it correctly. When I run this on android version less that 26 it works correctly but on version greater than 26 I get the error bellow
2019-10-30 17:57:45.206 8589-8697/com.otemainc.foodfuzzapp E/Volley: [355] NetworkDispatcher.processRequest: Unhandled exception java.lang.IllegalArgumentException: Request#getParams() or Request#getPostParams() returned a map containing a null key or value: (client, null). All keys and values must be non-null.
java.lang.IllegalArgumentException: Request#getParams() or Request#getPostParams() returned a map containing a null key or value: (client, null). All keys and values must be non-null.
at com.android.volley.Request.encodeParameters(Request.java:478)
at com.android.volley.Request.getBody(Request.java:466)
at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:275)
at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:249)
at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:94)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:123)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
我是否需要更新代码以处理新版本?如果是,那是什么?
Could there be something that I need to update on my code to take care of the new version? If yes what is it?
推荐答案
它在堆栈跟踪中说明了
It says it in the stacktrace
java.lang.IllegalArgumentException:Request#getParams() 或 Request#getPostParams() 返回一个包含空键或值的映射:(客户端,空).所有键和值都必须非空.
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("orderId",orderId);
params.put("client", client); // <<< HERE
params.put("name", prodid);
params.put("seller", Seller);
params.put("amount", amount);
params.put("quantity",quantity);
params.put("longitude",String.valueOf(longi));
params.put("latitude",String.valueOf(lat));
params.put("location",location);
return params;
}
您的 client
值为 null
: params.put("client", client);
这篇关于Volley:[355] NetworkDispatcher.processRequest:未处理的异常 java.lang.IllegalArgumentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!