列表视图在android studio中没有显示任何值

哈里

目前,我正在尝试开发使用PHP和Android Studio的项目。我正在使用列表视图。我已经用过谷歌其他教程,但没有找到任何答案,但是在使用列表视图时仍然有问题。

05-30 23:10:15.592    7820-7849/com.example.ayim.madoc D/All Products:﹕ {"success":1,"patient":[{"id":"1","name":"Ikhwan Johari"},{"id":"2","name":"Ruminah Bedah"},{"id":"3","name":"Kamal Sado"}]}
05-30 23:10:15.592    7820-7849/com.example.ayim.madoc W/System.err﹕ org.json.JSONException: No value for idPatient
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at org.json.JSONObject.get(JSONObject.java:354)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at org.json.JSONObject.getString(JSONObject.java:510)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at com.example.ayim.madoc.ListPatient$LoadAllPatient.doInBackground(ListPatient.java:112)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at com.example.ayim.madoc.ListPatient$LoadAllPatient.doInBackground(ListPatient.java:69)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:234)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
05-30 23:10:15.593    7820-7849/com.example.ayim.madoc W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
05-30 23:10:15.594    7820-7849/com.example.ayim.madoc W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
05-30 23:10:15.594    7820-7849/com.example.ayim.madoc W/System.err﹕ at java.lang.Thread.run(Thread.java:838)

这是我的堆栈显示的内容。来自数据库的值已获取,但未显示在列表视图中。我不知道该如何解决。谁能帮我?

我在这个Android Studio中仍然是新手。谢谢你。

这是我的Java代码。

public class ListPatient extends ListActivity {

    //String intentID = getIntent().getExtras().getString("id");
    // Progress Dialog
    private ProgressDialog pDialog;

    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> patientList;

    JSONArray patient = null;

    TextView idShow;

    private static final String list_url = "http://104.223.3.210/madoc/all_patient.php";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_patient);



         idShow = (TextView) findViewById(R.id.id);
        idShow.setText(getIntent().getExtras().getString("id"));


        // Hashmap for ListView
        patientList = new ArrayList<HashMap<String, String>>();

        // Loading products in Background Thread
        new LoadAllPatient().execute();

        // Get listview
        ListView lv = getListView();
    }



    class LoadAllPatient extends AsyncTask<String, String, String> {


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(ListPatient.this);
            pDialog.setMessage("Loading products. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        @Override
        protected String doInBackground(String... params) {



            try {

                List<NameValuePair> paras = new ArrayList<NameValuePair>();
                // getting JSON string from URL
                paras.add(new BasicNameValuePair("id", getIntent().getExtras().getString("id")));
                JSONObject json1 = jParser.makeHttpRequest(list_url, "POST", paras);
                Log.d("All Products: ", json1.toString());

                // Checking for SUCCESS TAG
                int success = json1.getInt("success");

                if (success == 1) {

                    patient = json1.getJSONArray("patient");

                    // looping through All Products
                    for (int i = 0; i < patient.length(); i++) {
                        JSONObject c = patient.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString("idPatient");
                        String name = c.getString("name");

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put("id", id);
                        map.put("name", name);

                        // adding HashList to ArrayList
                        patientList.add(map);
                    }
                } else {


                    idShow.setText("No Patient");
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }


            return null;
        }

        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    ListAdapter adapter = new SimpleAdapter(
                            ListPatient.this, patientList,
                            R.layout.list_patient, new String[] { "id",
                            "name"},
                            new int[] { R.id.id, R.id.name });
                    // updating listview
                    setListAdapter(adapter);
                }
            });

        }
    }

}
弗拉基米尔·佩特拉科维奇

这里抛出异常:

String id = c.getString("idPatient");

"idPatient"JSON中没有密钥。尝试将其替换为"id"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Android Studio 列表视图

从列表视图Android中删除视图/值

在列表视图Android中显示/隐藏按钮,

如何在列表视图android中删除列表视图项?

如何从Android中的列表视图中删除列表视图项

在Android Studio中创建了一个简单的按钮,但没有任何显示

为什么我的列表没有显示在Android Studio中?

如何通过比较android中的值来显示列表视图

在输出上显示列名(Android列表视图)

android显示白屏,而不是列表视图

Android中列表视图底部的按钮

Android:单击“视图”下拉列表中的textView

在列表视图中的Android中的Json解析

Android,列表项中的文本视图对齐

android中的列表视图边框设计

动态表视图(就像 android 中的不可滚动列表视图)

在android中滚动列表视图时,文本值会在自定义列表视图中更改?

Android:在列表片段中的列表视图之外单击

在android中对列表进行排序以获取列表视图

如何在列表视图android中删除特定的列表项?

Android我的列表视图不显示所有项目

删除 Android Studio 中列表视图项中的默认填充

如何显示从android中的sqlite数据填充的列表视图

在Android中显示冗余数据的列表视图

如何在片段Android Studio Kotlin中实现列表视图

Android Studio logcat没有任何显示可显示添加关键宽度滤镜

在Android上单击列表视图项时,过滤列表视图未显示正确的结果

Android中具有两个列表视图的活动

如何在Android中对列表视图进行拉动刷新时禁用列表视图项上的onclickListener?