黑马程序员技术交流社区
标题:
Unresolved compilation problem: 这是什么问题啊
[打印本页]
作者:
djx900
时间:
2012-3-7 16:55
标题:
Unresolved compilation problem: 这是什么问题啊
package cn.itcast.eclips;
import java.sql.Statement;
import java.util.*;
public class demo1 {
/**
* @param args
*/
public static void main (String[] args) {
TreeSet ts = new TreeSet();
ts.add(new Student("li",22,33));
ts.add(new Student("zhang",21,99));
ts.add(new Student("wang",23,20));
ts.add(new Student("dong",25,50));
ts.add(new Student("ka",37,60));
Iterator it = ts.iterator();
while( ((Iterator) it).hasNext())
{
Student stu = (Student)it.next();
System.out.print(stu.getGrade()+"..."+stu.getAge()+"..."+stu.getGrade() );
}
}
class Student implements Comparable
private String name;
private int age;
private int grade;
public Student(String name,int age,int grade)
{
this.name = name;
this.age = age;
this.grade = grade;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age)
{
this.age = age;
}
public int getGrade()
{
return grade;
}
public void setGrade(int grade)
{
this.grade = grade;
}
public int compareto(Object obj)
{
Student si = (Student)obj;
if(!(obj instanceof Student))
throw new RuntimeException("不是学生");
Student s = (Student)obj;
if(this.grade>s.grade)
return 1;
if(this.grade<s.grade)
return -1;
if(this.grade==s.grade)
return this.name.compareTo(s.name);
}
}
复制代码
作者:
djx900
时间:
2012-3-7 16:56
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at cn.itcast.eclips.demo1.main(demo1.java:12)
总是显示这个错误 高手指教下啊
作者:
杨毅
时间:
2012-3-7 17:00
你运行的不是这个主函数吧? {:soso_e141:}
作者:
H07000223
时间:
2012-3-7 17:09
编译有错误~~~编译么通过,有不合语法的错~~~
作者:
djx900
时间:
2012-3-7 17:10
代码这么写的 没别的文件都
作者:
djx900
时间:
2012-3-7 17:23
求 语法 错误
作者:
H07000223
时间:
2012-3-7 21:06
public int compareto(Object obj)
这个方法名错了应该是compare
T
o
作者:
许圣建
时间:
2012-3-7 21:47
本帖最后由 许圣建 于 2012-3-7 21:49 编辑
.Error: Unresolved
compilation problem
原因是compareTo()没覆写到,你是to小写了,楼主大小写很不规范,dome1首字母也没大写
另外我想问问,第22行代码为什么非要写(Iterator it)it.next()?很奇怪,难道迭代器内部实现代码有问题,不能保证next()方法返回一个迭代器?
提醒一下,大部分异常都是可以通过名称来分辨的,名称那么长都是有意义的。
作者:
校长
时间:
2015-10-18 23:47
是否最末尾多了个“ } ” ?
作者:
baoyuzhuo
时间:
2016-4-12 00:24
看来规范很重要啊,我也遇到这个问题了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2