我一直得到这两个错误,似乎无法理解为什么。这些错误突然出现在其他方法中,进一步在同一类中。我试图找到双重声明但找不到任何声明。另外,我注意在另一种方法中编写方法。将非常感谢帮助! :)
public void connectStudentToCourse(long studentID, String courseID)
{
if (studentID >= 0 && courseID != null)
{
boolean flag = false;
Course tempCourse = new Course(courseID);
tempCourse = sData.getCourses().get( sData.getCourses().indexOf(courseID) );
Student stu = new Student(studentID);
stu = sData.getStudents().get( sData.getStudents().indexOf(studentID) );
if (tempCourse != null && stu != null)
{
if (tempCourse.getPreCourses() != null)
for (Course c : tempCourse.getPreCourses())
{
for (Course passed : stu.getCompletedCourses())
{
if (passed.equals(c))
flag = true;
}
if (flag == false)
{
MyFileLogWriter.writeToLogFile("Failed to connect Student "+studentID+" to course "+courseID+"\n", false);
return;
}
else flag = false;
}
if (tempCourse.addStudent(stu))
{
if (stu.addCourse(tempCourse))
{
MyFileLogWriter.writeToLogFile("Student "+stu.getId()+" connected to course "+tempCourse.getCourseID()+" successfully\n", false);
return;
}
else //RollBack
tempCourse.removeStudent(stu);
}
}
}
MyFileLogWriter.writeToLogFile("Failed to connect Student "+studentID+" to course "+courseID+"\n", false);
}
答案 0 :(得分:0)
我认为您必须在2nd if语句中添加左括号并关闭它,可能会解决您的问题......
答案 1 :(得分:0)
只有当我从班级中删除所有有问题的方法时,我才注意到了#34;}"在他们上面的方法中。 Eclipse没有显示这个缺失的大括号,直到我删除了所有剩下的代码,所以在删除之前我无法分辨它丢失的位置。我添加了缺少的大括号,并将其余有问题的方法重新粘贴到课堂中,所有错误都消失了!解决方案比我预期的要简单得多。 @ PM77-1,@ Jon Skeet和@Andreas - 你们都是LEGENDS!非常感谢!! :)