gpt4 book ai didi

android - logcat 中的 Volley 错误消息 "null"

转载 作者:行者123 更新时间:2023-11-29 19:07:22 26 4
gpt4 key购买 nike

<分区>

我已经向我 friend 的服务器发出了一个发布请求。在我的 logcat 中,我收到 volley 错误消息为 null 并且没有响应正文或网络响应代码。

我使用了 VolleySingleton 模式并为我的操作提出了正确类型的请求。从 postman 那里测试应用程序,一切似乎都运行良好,但在物理设备上运行它,我无法在日志中找到任何消息。

这是我的代码:

public class VolleySingleton {

public RequestQueue requestQueue;
public Context appContext;
public static VolleySingleton instanceVolley;

public VolleySingleton(Context mContext) {
this.appContext = mContext;
this.requestQueue = getRequestQueue();
}

public static synchronized VolleySingleton getVolleySingleton(Context context){
if (instanceVolley == null){
return new VolleySingleton(context);
}
return instanceVolley;
}

public RequestQueue getRequestQueue(){
if (requestQueue == null){
requestQueue = Volley.newRequestQueue(appContext.getApplicationContext());
}
return requestQueue;
}

public <T> void addToRequestQueue(Request<T> request){
getRequestQueue().add(request);
}

}

此外,这是我的发帖请求:

JSONObject userObject = new JSONObject();
JSONObject paramsObject = new JSONObject();
try {
paramsObject.put("name", fullName);
paramsObject.put("phone", mobile_No);
paramsObject.put("gender", Gender);
paramsObject.put("dob", unixTime);
userObject.put("user", paramsObject);
} catch (JSONException e) {
e.printStackTrace();
}

JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Constants.TING_SIGNUP_ENDPOINT, userObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, "Response is:\t " + response.toString());
Snackbar.make(findViewById(android.R.id.content), R.string.sign_up_msg, Snackbar.LENGTH_LONG).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent signUpIntent = new Intent(SignUpActivity.this, LoginActivity.class);
signUpIntent.putExtra("fullNameKey", fullName);
startActivity(signUpIntent);
}
}, 3000);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Failed with error msg:\t" + error.getMessage());
Log.d(TAG, "Error StackTrace: \t" + error.getStackTrace());

if (error.getMessage() == null){
createUser();
}

}
}) {
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
int respCode = response.statusCode;
Log.d(TAG, "Response Code is:\t" + respCode);
return super.parseNetworkResponse(response);
}
};

jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(60000, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
VolleySingleton.getVolleySingleton(this).addToRequestQueue(jsonObjectRequest);

请问是什么问题?谢谢

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com