Hi
Im trying to get my program to sort an array of objects but I get "java.lang.ClassCastException:" at Arrays.sort(stud) below. So java thinks I have casted an object of the wrong kind. But the "compareTo" method has arg Student and "stud" is clearly a collection of Student objects. What did I do?
-------------------------------------------------------------------
import java.io.IOException;
import java.util.*;
import javax.swing.*;
public class Betygslistor {
Fileread F;
Student[] stud;
public static void main(String[] args) throws IOException{
new Betygslistor();
}
public Betygslistor() throws IOException{
F=new Fileread();
arrangeStuds();
}
public void arrangeStuds(){
stud=F.getStuds(); //gets objects created in "Fileread F"
Arrays.sort(stud); ***Error here***
}
}
------------------------------------------------------------
public class Student implements Comparable<Student>{
(fields)*
public int compareTo(Student S) {
String SeName=S.geteName();
int comp=this.eName.compareTo(SeName);
return(comp);
}
.........
Im trying to get my program to sort an array of objects but I get "java.lang.ClassCastException:" at Arrays.sort(stud) below. So java thinks I have casted an object of the wrong kind. But the "compareTo" method has arg Student and "stud" is clearly a collection of Student objects. What did I do?
-------------------------------------------------------------------
import java.io.IOException;
import java.util.*;
import javax.swing.*;
public class Betygslistor {
Fileread F;
Student[] stud;
public static void main(String[] args) throws IOException{
new Betygslistor();
}
public Betygslistor() throws IOException{
F=new Fileread();
arrangeStuds();
}
public void arrangeStuds(){
stud=F.getStuds(); //gets objects created in "Fileread F"
Arrays.sort(stud); ***Error here***
}
}
------------------------------------------------------------
public class Student implements Comparable<Student>{
(fields)*
public int compareTo(Student S) {
String SeName=S.geteName();
int comp=this.eName.compareTo(SeName);
return(comp);
}
.........
