java试图打印数组参数错误
我试图打印出一个数组的内容,但当我在数组中循环打印元素时遇到了一个问题。它给我的错误是:
FileRead类型中的方法ImportItems()不适用于参数(int)
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class FileRead {
public String[] ImportTeams(){
String[] Teams;
BufferedReader br = null;
int linecount = 0;
try {
br = new BufferedReader(new FileReader("filepath"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
while (br.readLine() != null){
linecount ++;
}
br.close();
br = new BufferedReader(new FileReader("filepath"));
if (linecount % 2 != 0) {
linecount ++;
}
Teams = new String[linecount];
String teamcounter;
int arraycount = 0;
while ((teamcounter = br.readLine()) != null) {
Teams[arraycount] = teamcounter;
arraycount++;
}
return Teams;
} catch (IOException e1) {
e1.printStackTrace();
}
return null;
}
public static void main(String args[]){
FileRead fr = new FileRead();
for(int i =0; i <fr.ImportTeams().length; i++){
System.out.println(fr.ImportTeams(i));
}
}
}
# 1 楼答案
您的方法ImportItems没有任何参数
使用
# 2 楼答案
应该是:
从
array
访问元素时,需要使用array[index]
语法