通过Android应用程序注册教师?

时间:2018-03-30 07:30:05

标签: java android

问题是关于通过android app将教师注册到数据库中。     当我使用给定的Android模拟器运行应用程序时,它运行良好,但当使用我的个人Android设备运行时,它会生成TIMEOUT错误。

private void registerUser()
{
   final String id=e1.getText().toString().trim();
   final String name=e2.getText().toString().trim();
   final String password=e3.getText().toString().trim();
   final String email=e4.getText().toString().trim();

   //String request
   //use post method in it as it takes values

   progressDialog.setMessage ("Registering User");
   progressDialog.show ();

   StringRequest stringRequest=new StringRequest(Request.Method.POST, Constants.URL_REGISTER,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                    //if there is no error this method will be executed
                        progressDialog.dismiss ();

                        try {
                            JSONObject jsonObject=new JSONObject (response);
                            Toast.makeText (getApplicationContext() ,jsonObject.getString ("message"),Toast.LENGTH_LONG).show ();
                            //jsonObject.getString ("message")
                        }catch (JSONException e){
                            e.printStackTrace ();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        progressDialog.hide ();

                        if(error instanceof NetworkError)
                            Toast.makeText (getApplicationContext (),"Network ERROR",Toast.LENGTH_LONG).show ();

                        if(error instanceof TimeoutError)
                            Toast.makeText (getApplicationContext (),"Time Out ERROR",Toast.LENGTH_LONG).show ();
                        //error.getMessage ()
                        if(error instanceof ServerError)
                            Toast.makeText (getApplicationContext (),"Server ERROR",Toast.LENGTH_LONG).show ();


                    }
                }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params=new HashMap<> ();
                params.put("Faculty_ID",id);
                params.put("Faculty_Name",name);
                params.put("Faculty_Password",password);
                params.put("Faculty_Email",email);
                return params;
            }
      };

     //RequestQueue requestQueue= Volley.newRequestQueue(this);
     //requestQueue.add(stringRequest);
     //    finish ();
     RequestHandler.getInstance (this).addToRequestQueue (stringRequest);
 }    

使用了phpmyadmin。 它只给出超时错误 * /

由于

1 个答案:

答案 0 :(得分:0)

在SocketTimeout&amp ;;的情况下设置重试策略。 ConnectionTimeout异常。 如果您已指定该政策,Volley会为您重试。

stringRequest.setRetryPolicy(new DefaultRetryPolicy(5000, 
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

有关详细信息click here