代碼太亂了,當自己寫時,懵逼了
// 創建學生對象并選課
public void createStudentAndSelectCours() {
//創建一個學生對象
student = new Student("1", "小明");
System.out.println("歡迎學生:" + student.name + "選課!");
//創建一個Scanner對象,用來接收從鍵盤輸入的課程ID
Scanner console = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
System.out.println("請輸入課程ID");
String courseId = console.next();
for (Course cr : coursesToSelect) {
if(cr.id.equals(courseId)) {
student.courses.add(cr);????????//這里報錯了,
}
}
}
}
報錯原因:
The method add(Collection_ArrayList.Course) in the type Set<Course> is not applicable for the arguments (CollectionMethod.Course)
2018-11-19
只看這個類,沒辦法解決問題啊。據我看你的這個異常信息,大概是非法參數異常。你的方法需要什么類型的參數?
信息提示你是在調用add方法時出現的問題,在本類中找不到錯誤,就應該順藤摸瓜找到方法定義處繼續找。