我正在开发一个程序,我需要扫描一个txt文件。保证txt文件在不同类型出现的地方和时间方面遵循特定格式。我尝试在我的程序中利用这一点,并使用扫描仪将我知道的部分全部放入整数,以及双打和字符串。当我运行我的程序它告诉我我有一个类型不匹配的异常,我知道由于txt文件的格式化,我的所有类型匹配,所以我如何让IDE认为这是好的。这里有问题的代码块是有帮助的。
ArrayList<Student>studentList=new ArrayList<Student>();//makes a new Array list that we can fill with students.
FileInputStream in=new FileInputStream("studentList.txt");//inputs the text file we want into a File Input Stream
Scanner scnr=new Scanner(in);//Scanner using the Input Stream
for(int i=0;i<scnr.nextInt();i++)//we know the first number is the number of minor students so we read in a new minor that number of times
{
Undergrad j=new Undergrad();//make a new undergrad
j.setDegreeType("MINOR");//make the degree type minor because we know everyone in this loop is a minor.
j.setFirstName(scnr.next());//we know the next thing is the student's first name
j.setLastName(scnr.next());//we know the next thing is the student's last name
j.setID(scnr.nextInt());//we know the next thing is the student's ID
j.setGPA(scnr.nextDouble());//we know the next thing is the student's GPA
j.setCreditHours(scnr.nextDouble());//we know the next thing is the student's credit hours
studentList.add(j);//Finally, we add j to the arraylist, once it has all the elements it needs
}
答案 0 :(得分:0)
计算机程序完全按照你告诉他们做的那样。
如果您创建的程序需要某些输入,并且该程序会告诉您&#34;意外输入&#34 ;;然后是两个合乎逻辑的解释:
长话短说:这不是IDE在这里弄错了。
因此&#34;策略&#34;这是: