我收到错误
PersonsInfoData[i] = PersonsInfoin.setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]);
“不兼容的类型:void无法转换为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());
}
}
答案 0 :(得分:1)
这是一个二传手语:
PersonsInfoin.setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]);
所以,并非所有setter都返回对象,在你的情况下,方法返回什么都不返回(void
),使你的语句等同于:
PersonsInfoData[i] = void
无效......
答案 1 :(得分:0)
我猜你正在尝试将值写入PersonsInfoData [i]。如果是,则用 -
替换该行 PersonsInfoData[i].setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]);