截击错误消息"null".在logcat中 [英] Volley Error Message "null" in logcat
本文介绍了截击错误消息"null".在logcat中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经向我朋友的服务器发出了发帖请求.在我的logcat中,我收到截击错误消息,为null,没有响应正文或网络响应代码.
I have made a post request to my friend's server. In my logcat I am getting volley error message as null and no response body or network response code.
我使用了VolleySingleton模式,并为我的操作提出了正确的请求类型.从邮递员测试该应用程序,似乎一切正常,但是在物理设备上运行该应用程序,我无法在日志中找到任何消息.
I have used the VolleySingleton pattern and made the right type of requests for my operation. Testing the app from postman, all seems to be working fine but running it on a physical device, I am not able to find any message in logs.
这是我的代码:
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);
}
}
另外,这是我的发帖请求:
Also, here is my post 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);
请问是什么问题?谢谢
推荐答案
尝试一下.
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Failed with error msg:\t" + error.getMessage());
Log.d(TAG, "Error StackTrace: \t" + error.getStackTrace());
// edited here
try {
byte[] htmlBodyBytes = error.networkResponse.data;
Log.e(TAG, new String(htmlBodyBytes), error);
} catch (NullPointerException e) {
e.printStackTrace();
}
if (error.getMessage() == null){
createUser();
}
}
这篇关于截击错误消息"null".在logcat中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文