import java.util.*;
public class Employee implements Comparable {
String name;
int age;
public Employee(String name,int age)
{
this.name=name;
this.age=age;
}

public String toString()
{
return "name"+this.name+"Age"+this.age;
} @Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
Employee temp=(Employee)o;
if(this.age==temp.age)
return 0;
else if(this.age>temp.age)
return 1;
else
return -1;

}

public static void main(String[] args) {
// TODO Auto-generated method stub
Employee[] employees=new Employee[]{
new Employee("jack",21),
new Employee("tom",23),
};
Arrays.sort(employees);

for(int i=0;i<employees.length;i++)
{
System.out.println(employees[i].toString());
}
}
}
报错说:java.lang.NoSuchMethodError: main
Exception in thread "main" 拜托各位!

解决方案 »

  1.   

    该类没有问题,你看一下环境变量配置有没有问题。还有可能是JDK版本。用1.5以上的应该没问题。
      

  2.   


    import java.util.*;public class Employee implements Comparable {
    String name;
    int age; public Employee(String name, int age) {
    this.name = name;
    this.age = age;
    } public String toString() {
    return "name" + this.name + "Age" + this.age;
    } public static void main(String[] args) {
    // TODO Auto-generated method stub
    Employee[] employees = new Employee[] { new Employee("jack", 21),
    new Employee("tom", 23), };
    Arrays.sort(employees); for (int i = 0; i < employees.length; i++) {
    System.out.println(employees[i].toString());
    }
    }

    public int compareTo(Object o) {
    // TODO Auto-generated method stub
    Employee temp = (Employee) o;
    if (this.age == temp.age)
    return 0;
    else if (this.age > temp.age)
    return 1;
    else
    return -1; }
    }没问题,上面的代码在我机子上运行通过!只是去掉了compareTo方法上面的@Override
      

  3.   

    @Override没问题,这个只是MyEclipse6.0的一个漏洞!问题不在这个上面!
      

  4.   


    这个是一个接口 你可以查 JDK文档
      

  5.   

    楼主明白@Override什么意思吗?