我有一段代码用于从第二个文件中收集文件列表,在最终将每个单独的对象添加到ArrayList之前将它们格式化为“Statistic”对象和单个数组。不幸的是,我收到错误没有为add(int,Statistic)找到合适的方法。任何帮助将不胜感激。相应的代码如下。
Statistic tempStatistic=new Statistic();
Statistic[] statisticsToAdd=new Statistic[importFileList.size()];
ArrayList<Statistic> totalStatistics=new ArrayList<Statistic>();
for (int i=0; i<totalStatistics.size(); i++) {
statisticsToAdd=getStatistics(importFileList.get(i));
for (int j=0; j<statisticsToAdd.length; j++) {
//statisticsToAdd[j]=new Statistic();
tempStatistic=statisticsToAdd[j];
totalStatistics.add(tempStatistic);
}//end inner FOR
}//end outer FOR
Statistic[] totalStatisticsArray=totalStatistics.toArray();
return totalStatisticsArray;
答案 0 :(得分:0)
您的totalStatistics变量类型错误。它应该是:
ArrayList<Statistic> totalStatistics=new ArrayList<Statistic>();