无法从数据库获取pdf

时间:2019-04-28 09:22:36

标签: java android pdf xampp

我正在处理一个项目,并且一切正常,但是当我单击获取按钮时,它并没有获取pdf并在列表视图中显示它们。

它仅显示过程对话框,并且对话框在半秒后消失

我尝试了依赖关系,但是一切都好了,gradle构建没有错误

private void getPdfs() {

    progressDialog.setMessage("Fetching Pdfs... Please Wait");
    progressDialog.show();
    StringRequest stringRequest;
    stringRequest = new StringRequest(Request.Method.POST, PDF_FETCH_URL,

            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {


                    progressDialog.dismiss();
                    try {
                        JSONObject obj = new JSONObject(response);
                        Toast.makeText(MCA.this,obj.getString("message"), Toast.LENGTH_SHORT).show();

                        JSONArray jsonArray = obj.getJSONArray("pdfs");

                        for(int i=0;i<jsonArray.length();i++){

                            //Declaring a json object corresponding to every pdf object in our json Array
                            JSONObject jsonObject = jsonArray.getJSONObject(i);
                            //Declaring a Pdf object to add it to the ArrayList  pdfList
                            Pdf pdf  = new Pdf();
                            String pdfName = jsonObject.getString("name");
                            String pdfUrl = jsonObject.getString("url");
                            pdf.setName(pdfName);
                            pdf.setUrl(pdfUrl);
                            pdfList.add(pdf);

                        }

                        pdfAdapter=new PdfAdapter(MCA.this,R.layout.list_layout, pdfList);

                        listView.setAdapter(pdfAdapter);

                        pdfAdapter.notifyDataSetChanged();

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                }
            },


            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }
    );

    RequestQueue request = Volley.newRequestQueue(this);
    request.add(stringRequest);

}
}

0 个答案:

没有答案