Php 使用android无法从服务器获取价值到我的文本视图

Php 使用android无法从服务器获取价值到我的文本视图,php,android,mysql,android-volley,Php,Android,Mysql,Android Volley,我是android新手,这里如果我选择忘记密码链接,它应该转到下一个活动,如果我写了正确的电子邮件,那么它应该从服务器设置正确的密码。但我没有从服务器获得价值。 这是我的ForgotPassword.java: public class ForgotPasswordActivity extends AppCompatActivity { private String fremail; private ProgressDialog pDialog; protected EditText f

我是android新手,这里如果我选择忘记密码链接,它应该转到下一个活动,如果我写了正确的电子邮件,那么它应该从服务器设置正确的密码。但我没有从服务器获得价值。 这是我的ForgotPassword.java:

public class ForgotPasswordActivity extends AppCompatActivity {

 private String fremail;
 private ProgressDialog pDialog;
 protected EditText femail;
 protected Button mSubmitButton;
 TextView pas;

 private static String url_create_book = "http://cloud......com/broccoli/fpassword.php";


 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_forgot_password);
  Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  setSupportActionBar(toolbar);
  getSupportActionBar().setDisplayHomeAsUpEnabled(true);

  pas = (TextView) findViewById(R.id.pas);
  femail = (EditText) findViewById(R.id.feml);

  Button submit = (Button) findViewById(R.id.sbtn);
  submit.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {

    pDialog = new ProgressDialog(ForgotPasswordActivity.this);
    pDialog.setMessage("Please wait..");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(true);
    pDialog.show();
    fremail = femail.getText().toString();

    // new CreateNewProduct().execute();
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url_create_book,
     new Response.Listener < String > () {
      @Override
      public void onResponse(String response) {
       pDialog.dismiss();

       try {
        JSONObject object = new JSONObject(response);
        JSONArray jsonArray = object.getJSONArray("result");
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        // fetch password from JSON
        String password = jsonObject.getString("password");
        // use password in textviewfemail.setText(password, TextView.BufferType.EDITABLE);
        pas.setText(password, TextView.BufferType.EDITABLE);
       } catch (JSONException e) {
        Toast.makeText(ForgotPasswordActivity.this, e.toString(), Toast.LENGTH_LONG).show();
       }


      }

     },

     new Response.ErrorListener() {
      @Override
      public void onErrorResponse(VolleyError error) {
       pDialog.dismiss();
       Toast.makeText(ForgotPasswordActivity.this, error.toString(), Toast.LENGTH_LONG).show();
      }
     }) {
     @Override
     protected Map < String, String > getParams() {
      Map < String, String > params = new HashMap < String, String > ();
      params.put("email", fremail);


      return params;
     }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(ForgotPasswordActivity.this);
    requestQueue.add(stringRequest);

   }

  });
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
   case android.R.id.home:
    onBackPressed();
    return true;
   default:
    return super.onOptionsItemSelected(item);
  }
 }

}

我得到了答案…我的php代码很好,我在上面发布了。问题在于@Pier Giorgio Misley告诉我的json对象和json数组。下面是我的更新活动:

 StringRequest stringRequest = new StringRequest(Request.Method.POST, url_create_book,
                        new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                pDialog.dismiss();

                                try {
                                    JSONObject object     = new JSONObject(response);

                                 //   JSONArray jsonArray   = object.getJSONArray(0);
                                  //  JSONObject jsonObject = jsonArray.getJSONObject(0);

// fetch password from JSON
                                    String password         = object.getString("password");
// use password in textviewfemail.setText(password, TextView.BufferType.EDITABLE);
                                    pas.setText(password, TextView.BufferType.EDITABLE);



                                }
                                catch (JSONException e) {
                                    Toast.makeText(ForgotPasswordActivity.this, e.toString(), Toast.LENGTH_LONG).show();
                                }
StringRequest-StringRequest=newstringrequest(Request.Method.POST,url\u create\u book,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
pDialog.disclose();
试一试{
JSONObject对象=新的JSONObject(响应);
//JSONArray JSONArray=object.getJSONArray(0);
//JSONObject JSONObject=jsonArray.getJSONObject(0);
//从JSON获取密码
字符串密码=object.getString(“密码”);
//在textviewfemail.setText中使用密码(密码,TextView.BufferType.EDITABLE);
pas.setText(密码,TextView.BufferType.EDITABLE);
}
捕获(JSONException e){
Toast.makeText(ForgotPasswordActivity.this,例如toString(),Toast.LENGTH_LONG).show();
}

通过调试,第一个对象和第一个数组为空或已填充?android新手..不知道如何调试..好的,那么你最好回到教程阶段..调试是要学习的第一个任务。在google上搜索“如何在android studio上调试”。无论如何,有一个按钮称为“调试”在程序的上半部分,单击左侧的一行,您将添加一个断点等等。但是首先请真正观看一些教程。我这样说只是因为如果您不知道如何调试,我们很难帮助您,因为您不知道程序的状态{“result”:[]}我从调试中了解到这是解析json的正确方法。主要问题是解析json。解析取决于json响应的指令。你知道如何将alertdialog box值发送到数据库…你尝试过这种类型的东西吗?让我们来看看。
{
    "password": ""
}
 StringRequest stringRequest = new StringRequest(Request.Method.POST, url_create_book,
                        new Response.Listener<String>() {
                            @Override
                            public void onResponse(String response) {
                                pDialog.dismiss();

                                try {
                                    JSONObject object     = new JSONObject(response);

                                 //   JSONArray jsonArray   = object.getJSONArray(0);
                                  //  JSONObject jsonObject = jsonArray.getJSONObject(0);

// fetch password from JSON
                                    String password         = object.getString("password");
// use password in textviewfemail.setText(password, TextView.BufferType.EDITABLE);
                                    pas.setText(password, TextView.BufferType.EDITABLE);



                                }
                                catch (JSONException e) {
                                    Toast.makeText(ForgotPasswordActivity.this, e.toString(), Toast.LENGTH_LONG).show();
                                }