2013-03-10 157 views
0

我需要您从MySQL数据库获取有关retreive数据的帮助。我不能将字符串添加到数组列表。 我的名单宣布如何将字符串转换为ArrayList

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 show reportList ---> []

感谢您的回答!

+0

你在哪里声明reportList。写在这里,还有你面临的问题是什么? – stinepike 2013-03-10 04:34:40

+0

我的logcat在reportList上抛出[] – Ply 2013-03-10 04:39:45

+0

在使用它们创建新的'HandleListReport'对象之前,您是否调试过代码以查找变量的值 'reportID,userID,projectName,localWork,timeStart,timeEnd'? – 2013-03-10 04:46:47

回答

0

创建字符串的列表

List<String> list ...... 

list.add(String) 

然后list.toArray()方法

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

0

它似乎你正试图将对象的HandleListReport存储在arraylist中。在这种情况下使用以下方法来启动

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

它似乎没有工作,reportList仍然为空。 – Ply 2013-03-10 04:51:22

+0

你是从哪里发起arraylist?在oncreate()中启动它。并在结束循环后检查reportList.size() – stinepike 2013-03-10 05:02:57

+1

它不必在'onCreate()'。只要它是一个成员变量,那么它应该没问题 – codeMagic 2013-03-10 05:04:11

0

似乎变量report_data的长度为0,所以元素不会添加名单。