没有输出。并没有错误

时间:2017-04-23 12:49:26

标签: php android mysql

这个php

  <?php 

require_once '../includes/DbOperations.php';

$response = array(); 
$array=[];
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['receiver']) and isset($_POST['type']) and isset($_POST['dept']) and isset($_POST['sem']) and isset($_POST['section'])){
    $db = new DbOperations(); 


        $notice = $db->getAllStudentNotice($_POST['receiver'], $_POST['type'], $_POST['dept'], $_POST['sem'], $_POST['section']);
        while($user = mysqli_fetch_assoc($notice)){
        $response['error'] = false; 
        $response['datetime'] = $user['datetime'];
        $response['title'] = $user['title'];
        $response['content'] = $user['content'];
        $response['sender'] = $user['sender'];
        $response['type'] = $user['type'];
        $response['dept'] = $user['dept'];
        $response['sem'] = $user['sem'];
        $response['section'] = $user['section'];
        $array[]=$response;
    }

    }else{
    $response['error'] = true; 
    $response['message'] = "Required fields are missing";
    }
  }

  echo json_encode($array);

这是来自服务器的json

  [{"error":false,"datetime":"2017-04-18 16:08:35","title":"sds","content":"czxzx","sender":"principal","type":"All","dept":"computer science","sem":"1st","section":"All"}
 ,{"error":false,"datetime":"2017-04-19 20:59:37","title":"first","content":"hi,\r\nnice to meet u.","sender":"HOD","type":"individual","dept":"computer science","sem":"1st","section":"A"}]

这是我的活动代码

   private void loadRecyclerViewData(){
    final String receiver=SharedPrefManager.getInstance(this).getUsername();
    final String type="Individual";
    final String dept=SharedPrefManager.getInstance(this).getUserDept();
    final String sem=SharedPrefManager.getInstance(this).getUserSem();
    final String section=SharedPrefManager.getInstance(this).getUserSection();



    progressDialog.show();

    StringRequest stringRequest = new StringRequest(
            Request.Method.POST,
            Constants.URL_GET_STUDENT_NOTICE,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    progressDialog.dismiss();
                    try {
                        JSONObject obj = new JSONObject(response);
                        if(!obj.getBoolean("error")){
                            JSONArray array=obj.getJSONArray(response);

                            for(int i=0;i<array.length();i++){
                                JSONObject o=array.getJSONObject(i);
                                Item item=new Item(
                                        o.getString("datetime"),
                                        o.getString("title"),
                                        o.getString("content"),
                                        o.getString("sender"),
                                        o.getString("sendermail"),
                                        o.getString("receiver"),
                                        o.getString("type"),
                                        o.getString("dept"),
                                        o.getString("sem"),
                                        o.getString("section")
                                );
                                listitem.add(item);

                            }
                            ItemAdapter adapter=new ItemAdapter(getApplicationContext(),listitem);
                            rvItem.setAdapter(adapter);

                        }else{
                            Toast.makeText(
                                    getApplicationContext(),
                                    obj.getString("message"),
                                    Toast.LENGTH_LONG
                            ).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    progressDialog.dismiss();

                    Toast.makeText(
                            getApplicationContext(),
                            error.getMessage(),
                            Toast.LENGTH_LONG
                    ).show();
                }
            }
    ){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("receiver",receiver);
            params.put("type", type);
            params.put("dept", dept);
            params.put("sem", sem);
            params.put("section", section);

            return params;
        }

    };

    RequestHandler.getInstance(this).addToRequestQueue(stringRequest);
}

这是logcat的最后几行

   17:56:11.432 2057-2494/com.google.android.gms.persistent E/NetworkScheduler.SR: Invalid parameter app
  04-23 17:56:11.432 2057-2494/com.google.android.gms.persistent E/NetworkScheduler.SR: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
   04-23 17:56:11.440 18825-18825/? E/memtrack: Couldn't load memtrack module (No such file or directory)
  04-23 17:56:11.440 18825-18825/? E/android.os.Debug: failed to load memtrack module: -2
  04-23 17:56:12.180 1303-1317/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property

                                             [ 04-23 17:56:12.189 18869:18869 D/         ]
                                             HostConnection::get() New Host Connection established 0x99f5a400, tid 18869


                                             [ 04-23 17:56:12.235 18869:18912 D/         ]
                                             HostConnection::get() New Host Connection established 0x99f5a600, tid 18912
      04-23 17:56:16.943 18869-18869/com.example.chandan.projectfinal E/RecyclerView: No adapter attached; skipping layout

如果我输入progressDialog.dismiss();如下所示,进度对话框不会关闭。

   try {
                        JSONObject obj = new JSONObject(response);
                        progressDialog.dismiss();

如果我输入progressDialog.dismiss();如下图所示,进度对话框将关闭。

try {
             progressDialog.dismiss();

                        JSONObject obj = new JSONObject(response);

0 个答案:

没有答案