0
我得到一个错误与错误与文件阅读器
PersonsInfoData[i] = PersonsInfoin.setPersonsInfo(temp[0],temp[1],temp[2],temp[3],temp[4]);
“不兼容类型:无效不能coverted到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());
}
}
我认为你是正确的这个例子中,基于该错误消息,但:(1)一个“二传手”就像任何其他的方法,所以称它为“二传表”并非真正正确; (2)并非所有的setter都返回void,事实上,setter返回'this'对象以使它们可以链接是相当普遍的。 – ajb
@ajb我将编辑addint您的评论... thnks! –