android json to listview

两盒软妹~` 提交于 2020-01-25 07:25:21

问题


I working with android and JSON. I came so far, but I can's set the ID in the arraylist.The error will be in "json_data.getInt("ID")"

Can sombody help me

    public void klussenlijst()
    {
ArrayList<String> results = new ArrayList<String>();
        JSONObject json_data;
        mysql client = new mysql("http://www.****************/klussen.php?actie=klussen");

        try {
            client.Execute(RequestMethod.POST);
        } catch (Exception e) {
            e.printStackTrace();
        }

        String response = client.getResponse();

        try{;
        JSONArray jArray = new JSONArray(response);
             for(int i=0;i<jArray.length();i++){
             json_data = jArray.getJSONObject(i);
             results.add(json_data.getInt("ID"),(String) json_data.get("titel").toString());
            }
             filllist();


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

    }

回答1:


Not sure about your mysql() method and the huge lack of error handling, but are you sure that your project has allowed for INTERNET permissions in your AndroidManifest.xml file? Sounds to me like your getInt is not an int.



来源:https://stackoverflow.com/questions/4909646/android-json-to-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!