1

Hello guys can someone help me with this class? I am getting an error and I am only new to the android studio and mobile development. I'm in the process of learning and acquiring knowledge. Please help me.

RequestQueue requestQueue = Volley.newRequestQueue(this);

StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
    @Override
    public void onResponse(String response) {
        Toast.makeText(Register.this, response, Toast.LENGTH_LONG).show();
    }
}, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(Register.this, error.toString(), Toast.LENGTH_LONG).show();

    }
}) {

    @Override
    protected Map<String, String> getParams() throws AuthFailureError {

        Map<String, String> params = new HashMap<String, String>();
        params.put(NAME, pangaran);
        params.put(SURNAME, apelyido);
        params.put(ADDRESS, lugar);
        params.put(CONTACTNO, kontak);
        params.put(USERNAME, username1);
        params.put(PASSWORD, password1);
        return params;

    }
};

requestQueue.add(stringRequest);
vinS
  • 1,417
  • 5
  • 24
  • 37
pangs
  • 49
  • 1
  • 1
  • 7
  • 3
    Which class? Relax and post your code, describe what you are trying to achieve and what's not working. Without this, your question will be closed soon. – VPK Dec 08 '17 at 04:33
  • Just edited my question sir – pangs Dec 08 '17 at 04:36
  • it was working last night but when I run the code there is an error saying " com.android.volley.timeouterror " – pangs Dec 08 '17 at 04:37
  • can you help me sir? – pangs Dec 08 '17 at 04:44
  • timeouterror seems as HttpConnection timeout . make sure internet is working properly. Also you can assign the timeout yourself default is 30 seconds i guess. Only if its related to ConnectionTimeout. – ADM Dec 08 '17 at 04:55
  • @pangs try [this](https://stackoverflow.com/questions/21277123/volley-requestqueue-timeout) solution.might it help you to handle time out. – Harshad Prajapati Dec 08 '17 at 05:05
  • sir i'm new to this environment. How can i do that? – pangs Dec 08 '17 at 07:21

3 Answers3

5

May be you can increase the timeout to check the fine working of everything. Since you said that your code worked for you earlier, the possible reason could be your server took less time to respond to your request which may not be same at all the time due to traffics.
Try adding following lines to you existing code.

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

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

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

        }
    });
devgun
  • 1,003
  • 13
  • 33
1

see this link, hope it will help you to set the time for the volley.

and if it doesn't help just let me know.

UPDATED

At the end i have inserted the code to change the default time set by volley, you can set time by your self and it should be in milliseconds.

RequestQueue requestQueue = Volley.newRequestQueue(this);

StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
    Toast.makeText(Register.this, response, Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
    Toast.makeText(Register.this, error.toString(), Toast.LENGTH_LONG).show();

}
}) {

@Override
protected Map<String, String> getParams() throws AuthFailureError {

    Map<String, String> params = new HashMap<String, String>();
    params.put(NAME, pangaran);
    params.put(SURNAME, apelyido);
    params.put(ADDRESS, lugar);
    params.put(CONTACTNO, kontak);
    params.put(USERNAME, username1);
    params.put(PASSWORD, password1);
    return params;

}
};

//10000 is the time in milliseconds adn is equal to 10 sec
stringRequest.setRetryPolicy(new DefaultRetryPolicy(
            10000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

requestQueue.add(stringRequest);
Community
  • 1
  • 1
Paras Verma
  • 129
  • 9
  • hey sir can you help me pls? i still dont get it.In what part of my code where i will insert your suggestions? as i've said im new to android programming and mobile development – pangs Dec 08 '17 at 06:50
  • I have updated your code in my answer. check it out. – Paras Verma Dec 08 '17 at 07:01
  • you should check this using some other internet, there may be some speed issue in your current internet connection. – Paras Verma Dec 08 '17 at 07:22
1

For Me : that just for your "VPN" , turn off your "VPN"