gpt4 book ai didi

java - 文件读取器错误

转载 作者:行者123 更新时间:2023-12-02 13:31:02 24 4
gpt4 key购买 nike

我遇到错误

PersonsInfoData[i] = PersonsInfoin.setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]); 

"Incompatible types: void cannot be coverted to PersonsInfo"

public void readFile(String fileName)
{
// Try to read in the data and if an exception occurs go to the Catch section
try
{
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));

int i = 0; // i is used as the line counter
String line; // line is used to temporarily store the line read in from the data file

// Read a line from the data file into the buffer and then check whether
// it is null. The while loop continues until a line read in is null.
while ((line = br.readLine()) != null)
{
// Split the line of data (from the text file) and put each entry into the
// temporary array - temp[]
String[] temp = line.split(",");
// Save each entry into its respective PCDataRecord object.
PersonsInfoData[i] = PersonsInfoin.setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]);
i++; // Increment i so we can keep a count of how many entries have been read in.
}
numberOfEntries = i; // Set numberOfEntries equal to i, to remember how many entries are now in the array
br.close(); // Close the BufferedReader
in.close(); // Close the DataInputStream
fstream.close(); // Close the FileInputStream
}
catch (Exception e)
{
System.err.println("Error Reading File: " + e.getMessage());
}
}

最佳答案

这是一个 setter 语句:

PersonsInfoin.setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]); 

因此,并非所有 setter 都返回对象,在您的情况下,该方法返回什么都不返回(void),使您的语句相当于执行以下操作:

PersonsInfoData[i] = void

这是无效的...

关于java - 文件读取器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43177238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com