凌空StringRequest不调用OnResponse方法

时间:2019-05-06 12:00:58

标签: java android android-volley

我是Android开发的新手,并且正在使用Volley将StringRequest发送到本地主机(这也是我的第一篇文章)。

没有连接错误,但似乎未调用OnResponse方法。以下代码有问题吗?我已经看过之前的问题,但似乎没有一个特定于我的代码的答案。

当运行该应用程序时,会在进度对话框出现时

UserLogin()方法被调用。

public void UserLogin(){

    progressDialog.setMessage("Please wait...");
    progressDialog.show();

    StringRequest stringRequest = new StringRequest(Request.Method.POST, hhtpUrl,
            new Response.Listener<String>() {

                @Override
                public void onResponse(String ServerResponse) {

                    Log.d("Debug", ServerResponse.toString());

                    progressDialog.dismiss();

                    //make sure server response matches what we want
                    //for a data match
                    if (ServerResponse.equalsIgnoreCase("login success")) {


                        Toast.makeText(MainActivity.this, "Logged In Succesfully", Toast.LENGTH_LONG).show();

                        finish();

                    } else {
                        Toast.makeText(MainActivity.this, ServerResponse, Toast.LENGTH_LONG).show();
                    }
                }

            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {

                    //hiding the progress dialogue after all tasks complete
                    progressDialog.dismiss();

                    Toast.makeText(MainActivity.this, volleyError.toString(), Toast.LENGTH_LONG).show();

                }
            }

    ){
        @Override
        protected Map<String, String> getParams(){
            Map<String, String> params = new HashMap<String, String>();
            params.put("Email", EmailHolder);
            params.put("Password", PasswordHolder);

            return params;
        }
    };

    stringRequest.setRetryPolicy(new RetryPolicy() {
        @Override
        public int getCurrentTimeout() {
            return 5000;
        }

        @Override
        public int getCurrentRetryCount() {
            return 5000;
        }

        @Override
        public void retry(VolleyError error) throws VolleyError {

        }
    });
    requestQueue.add(stringRequest);
}

0 个答案:

没有答案