0

关于从 mysql db 检索数据,我需要您的帮助。我无法将字符串添加到数组列表。我的清单声明

ArrayList<HandleListReport> reportList = new ArrayList<HandleListReport>();

这是我的代码

report_data = json.getJSONArray(TAG_REPORT_DATA);

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

                        //storing variable
                        JSONObject c = report_data.getJSONObject(i);
                        String reportID = c.getString(TAG_REPORT_ID);
                        String userID = c.getString(TAG_UID);
                        String projectName = c.getString(TAG_PROJECT_NAME);
                        String localWork = c.getString(TAG_LOCATION);
                        String timeStart = c.getString(TAG_TIME_START);
                        String timeEnd = c.getString(TAG_TIME_END);
                        Log.d(TAG_LOCATION, localWork);
                        // add data to Arraylist
                        reportList.add(new HandleListReport(reportID, userID, projectName, localWork, timeStart, timeEnd));

我的问题我的 listReport 缺少字符串数据。Logcat 显示报告列表 ---> []

感谢您的回答!

4

3 回答 3

0

好像变量report_data的长度为0,所以元素不加列表。

于 2013-03-10T05:47:01.343 回答
0

创建一个字符串列表

List<String> list ......

list.add(String)

然后 list.toArray() 方法

http://docs.oracle.com/javase/6/docs/api/java/util/List.html#toArray(T[])

于 2013-03-10T04:38:17.037 回答
0

看来您正在尝试将 HandleListReport 的对象存储在 arraylist 中。在这种情况下,使用以下命令启动

ArrayList<HandleListReport> reportList = new ArrayList<HandleListReport>();
于 2013-03-10T04:43:06.533 回答