即使在插入数据后,进度对话框仍继续旋转

时间:2018-03-24 05:00:14

标签: java php android json android-volley

我只是创建一个简单的注册模块。我写了下面的代码,它插入数据,但进度对话框继续旋转,它永远不会停止,但如果我检查我的数据库,数据是否正确插入。我正在使用排球框架。我是Android凌空的初学者,请告诉我哪里出错了。

registration.java

public class registration extends AppCompatActivity {
EditText Name,Email,Username,Password;
ProgressDialog dialog;
ProgressBar progressBar;
String Reg_url="------";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registration);
    Name=(EditText)findViewById(R.id.nametext);
    Email=(EditText)findViewById(R.id.email);
    Username=(EditText)findViewById(R.id.Username);
    Password=(EditText)findViewById(R.id.pass);
    dialog=new ProgressDialog(this);
    dialog.setTitle("Loading");
    dialog.setMessage("Please Wait a Momment");

    dialog.setCancelable(false);
}
public void SignUp(View view)
{
    if(TextUtils.isEmpty(Name.getText().toString()))
    {
        Name.setError("At least 5 charachters");
    }
    else if(TextUtils.isEmpty(Email.getText().toString()))
    {
        Email.setError("Enter a Valid Email");
    }
   else if(TextUtils.isEmpty(Username.getText().toString()))
    {
        Username.setError("At least 5 charachters");
    }
    else if(TextUtils.isEmpty(Password.getText().toString()))
    {
        Password.setError("At least 5 charachters");
    }
    else
    {
        dialog.show();
        StringRequest stringRequest=new StringRequest(Request.Method.POST, Reg_url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        try {
                            JSONArray jsonArray=new JSONArray(response);
                            JSONObject jsonObject=jsonArray.getJSONObject(0);
                            dialog.dismiss();
                            finish();
                            startActivity(new Intent(registration.this,MainActivity.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                dialog.dismiss();
                Toast.makeText(registration.this,"Connection Failed",Toast.LENGTH_LONG).show();
            }
        }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> map=new HashMap<String, String>();
                map.put("name",Name.getText().toString());
                map.put("email",Email.getText().toString());
                map.put("user_name",Username.getText().toString());
                map.put("password",Password.getText().toString());

                return map;
            }
        };
        int socketTimeout= 30000;
        RetryPolicy policy=new DefaultRetryPolicy(socketTimeout,DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
        stringRequest.setRetryPolicy(policy);
        RequestQueue requestQueue= Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
    }

}
}

我已在清单文件中添加了互联网的用户权限。 我有排球框架依赖排球1.1.0。 它会正确显示响应错误,但作为回应,如果我应用了一个不会显示但未插入数据的吐司。

我的PHP代码是:

<?php
require "connect.php";
$name = $_POST["name"];
$email =$_POST["email"];
$user_name =$_POST["user_name"];
$password =$_POST["password"];
$sql = "INSERT INTO `user_info`(`name`, `email`, `user_name`, `password`) VALUES ('$name','$email','$user_name','$password')";
$result = mysqli_query($con,$sql);
mysqli_close($con);
?>

2 个答案:

答案 0 :(得分:0)

像这样更改你的响应块

a = task.objects.filter(actual_date__isnull=False)
for x in a:
    x.project.worker.tasks+=1

编辑: @Override public void onResponse(String response) { Toast.makeText(registration.this,"Response :"+response,Toast.LENGTH_SHORT).show(); try { JSONArray jsonArray=new JSONArray(response); dialog.dismiss(); finish(); startActivity(new Intent(registration.this,MainActivity.class)); } catch (JSONException e) { e.printStackTrace(); } } }

PHP代码

Configure your php code in such a way that it returns a response during a network call. And then parse the response in the app side. Currently your try block is not getting executed due to no response from backend(even if the backend query is executed)

答案 1 :(得分:0)

您的try / catch块可能会失败。测试以确保是这种情况:a)在try / catch块上设置断点并在调试器中逐行运行它,直到找到导致错误被抛出的行,或者b)添加日志语句到包含e.getLocalizedMessage()的catch块,以便您可以看到错误输出,或者c)将dialog.dismiss()放入catch black并查看它是否消失。如果您收到错误消息并且不知道发布它的含义,我们将深入了解它。