代碼太亂了,當(dāng)自己寫時,懵逼了
// 創(chuàng)建學(xué)生對象并選課
public void createStudentAndSelectCours() {
//創(chuàng)建一個學(xué)生對象
student = new Student("1", "小明");
System.out.println("歡迎學(xué)生:" + student.name + "選課!");
//創(chuàng)建一個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
只看這個類,沒辦法解決問題啊。據(jù)我看你的這個異常信息,大概是非法參數(shù)異常。你的方法需要什么類型的參數(shù)?
信息提示你是在調(diào)用add方法時出現(xiàn)的問題,在本類中找不到錯誤,就應(yīng)該順藤摸瓜找到方法定義處繼續(xù)找。