he20041987 发表于 2008-3-15 19:56

初学者的异常问题?已解决

程序代码如下:
class Excep{
        int compute(int a,int b){
                return a/b;
        }
}

class Test{
        public static void main(String[] args){
                Excep excep=new Excep();
                try{
                        excep.compute(5,0);
                }catch(Exception e){
                        System.out.print("除数不能为零");
                }               
        }
}   

这里怎么编译是总是提示
d:\javawork\Exception.java:1: duplicate class: Excep
class Excep{
^
d:\javawork\Exception.java:7: duplicate class: Test
class Test{
^
Exception.java:12: cannot access Exception
bad class file: d:\javawork\Exception.java
file does not contain class Exception
Please remove or make sure it appears in the correct subdirectory of the classpath.
                }catch(Exception e){
                       ^
3 errors

[[it] 本帖最后由 he20041987 于 2008-3-15 20:04 编辑 [/it]]

千里冰封 发表于 2008-3-15 20:02

Exception是一个系统的类库,你的文件名还是叫别的名字吧

he20041987 发表于 2008-3-15 20:03

呵呵  还真的过去了 谢谢了

he20041987 发表于 2008-3-15 20:04

回复 2# 的帖子

呵呵  还真的过去了 谢谢了

sunkaidong 发表于 2008-3-15 20:06

lz我的可以编译通过...jcreator+jdk1.5

he20041987 发表于 2008-3-15 20:10

回复 5# 的帖子

这个我没有试 因为刚刚学java书本是1.42所以我有的是jdk1.42,至于JC现在还不想用,打算先把基本功打好牢。

sunkaidong 发表于 2008-3-15 20:12

其实没关系...可以用用..jcreator也很简单啊..用记事本不太容易找错...特别大小写..不过确实可以训练这方面的找错误能力

[[it] 本帖最后由 sunkaidong 于 2008-3-15 20:14 编辑 [/it]]

谁与争疯 发表于 2008-3-15 20:20

千里解决的速度真快啊。

页: [1]

编程论坛