Java 应该打印数组的所有值的方法只返回空值。
我在下面有一个构造函数,它从文本文件中读取并获取每一行并将其分配给多维数组中的一个部分Java 应该打印数组的所有值的方法只返回空值。,java,arrays,null,Java,Arrays,Null,我在下面有一个构造函数,它从文本文件中读取并获取每一行并将其分配给多维数组中的一个部分 public ValueToArray(int rowsI, int columnsI, File fileLocationI){ int i; int j; InputStream fileInputStream; BufferedReader bufferedReader; String line; ro
public ValueToArray(int rowsI, int columnsI, File fileLocationI){
int i;
int j;
InputStream fileInputStream;
BufferedReader bufferedReader;
String line;
rows = rowsI;
columns = columnsI;
count = 0;
fileLocation = fileLocationI;
array = new String[rows][columns];
try{
fileInputStream = new FileInputStream(fileLocation);
bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream, Charset.forName("UTF-8")));
for(i = 0; i < rows; i++){ // iterate through row
for(j = 0; j < columns; j++){ // iterate through column
while((line = bufferedReader.readLine())!= null){ // while the next line is not null
array[i][j] = line; // assign i-th j-th index as line (the input)
// System.out.println(array[i][j]);
count++;
}
}
}
bufferedReader.close();
}catch(Exception e){
e.printStackTrace();
}
}
我想知道我的方法,甚至我的构造函数有什么问题,导致了空值?我的IDE中似乎没有出现任何错误。for(I=0;Ifor(i = 0; i < rows; i++){ // iterate through row
for(j = 0; j < columns; j++){ // iterate through column
while((line = bufferedReader.readLine())!= null){ // while the next line is not null
array[i][j] = line; // assign i-th j-th index as line (the input)
// System.out.println(array[i][j]);
count++;
}
}
}
对于(j=0;j
在进入第二个for循环后,while循环将继续放置所有值并将它们覆盖到数组[0][0]。因此,在第一次迭代中,您的整个文件都将被读取,文件中的最后一行就是您在[0][0]中看到的那一行。之后,每次迭代都会跳过一段时间,因为文件中没有更多的行。因此,它们都有空值。for(i=0;i
在进入第二个for循环后,while循环将继续放置所有值并将它们覆盖到数组[0][0]。因此,在第一次迭代中,您的整个文件都将被读取,文件中的最后一行就是您在[0][0]中看到的那一行。之后,每次迭代都会跳过一段时间,因为文件中没有更多的行。因此,它们都有空值。for(i=0;i
在进入第二个for循环后,while循环将继续放置所有值并将它们覆盖到数组[0][0]。因此,在第一次迭代中,您的整个文件都将被读取,文件中的最后一行就是您在[0][0]中看到的那一行。之后,每次迭代都会跳过一段时间,因为文件中没有更多的行。因此,它们都有空值。for(i=0;i
在进入第二个for循环后,while循环将继续放置所有值并将它们覆盖到数组[0][0]。因此,在第一次迭代中,您的整个文件都将被读取,文件中的最后一行就是您在[0][0]中看到的那一行。之后,每次迭代都会跳过一段时间,因为文件中没有更多的行。因此,它们都有空值。所以试试这个
for(i = 0; i < rows; i++){ // iterate through row
for(j = 0; j < columns; j++){ // iterate through column
while((line = bufferedReader.readLine())!= null){ // while the next line is not null
array[i][j] = line; // assign i-th j-th index as line (the input)
// System.out.println(array[i][j]);
count++;
break;
}
}
}
for(i=0;i
试试这个
for(i = 0; i < rows; i++){ // iterate through row
for(j = 0; j < columns; j++){ // iterate through column
while((line = bufferedReader.readLine())!= null){ // while the next line is not null
array[i][j] = line; // assign i-th j-th index as line (the input)
// System.out.println(array[i][j]);
count++;
break;
}
}
}
for(i=0;i
试试这个
for(i = 0; i < rows; i++){ // iterate through row
for(j = 0; j < columns; j++){ // iterate through column
while((line = bufferedReader.readLine())!= null){ // while the next line is not null
array[i][j] = line; // assign i-th j-th index as line (the input)
// System.out.println(array[i][j]);
count++;
break;
}
}
}
for(i=0;i
试试这个
for(i = 0; i < rows; i++){ // iterate through row
for(j = 0; j < columns; j++){ // iterate through column
while((line = bufferedReader.readLine())!= null){ // while the next line is not null
array[i][j] = line; // assign i-th j-th index as line (the input)
// System.out.println(array[i][j]);
count++;
break;
}
}
}
for(i=0;i
您的输入文件中是否只有一行?未报告任何异常。什么是范围问题?我如何在