【发布时间】:2018-10-20 21:10:40
【问题描述】:
我想创建一个多维数组并将其作为方法中的参数传递,然后用元素填充 arrayList 并返回新版本的 arrayList 以便能够在不同的类中使用该数组,但我得到 java.lang .NoSuchMethodError:我认为问题在于我返回数组的方式。我搜索但找不到。我怎样才能正确地做到这一点?
这是我的代码;
public test{
public static List<List<String>> 2Darray=new ArrayList<List<String>>(); // TE ERROR IN THIS LINE
public List<List<String>> fillArray(List<List<String>> array){
BufferedReader in = null;
ArrayList<String> row = new ArrayList<String>();
try {
in = new BufferedReader(new FileReader("sampleFile.txt"));
String read = null;
while ((read = in.readLine()) != null) {
String[] splited = read.split("\\s+");
for(int i=0; i<splited.length ; i++){
row.add(splited[i]);
}
array.add(row);
}
} catch (IOException e) {
System.out.println("There was a problem: " + e);
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
}
return array;
}
【问题讨论】:
-
请包含完整的堆栈跟踪并告诉我们哪一行抛出异常
标签: java arraylist multidimensional-array return return-type