A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 武维京 高级黑马   /  2014-5-22 10:35  /  1182 人查看  /  5 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 武维京 于 2014-5-28 22:18 编辑
  1. package Exception;

  2. class FuShuException extends Exception{
  3.          FuShuException(String msg){
  4.                  super(msg);
  5.          }
  6. }
  7. class Demo4{
  8.         int div (int a,int b) throws FuShuException{
  9.                 if(b<0){
  10.                         throw new FuShuException("除数为负数");
  11.                         
  12.                 }
  13.                 return a/b;
  14.         }
  15. }


  16. public class ExceptionDemo4 {
  17.         public static void main(String[] args) {
  18.                 // TODO Auto-generated method stub
  19.        Demo4 d = new Demo4();
  20.        try{
  21.                int x = d.div(4, -1);
  22.        }
  23.        catch(FuShuException e){
  24.                System.out.println(e.toString());
  25.                
  26.        }
  27.        finally{
  28.                System.out.println("finally");//finally中存在的是一定会被执行的代码。
  29.        }
  30.        System.out.println("ocer");
  31.         }

  32. }
  33. 在eclipse中报错:
  34. finally
  35. Exception in thread "main" java.lang.NoSuchMethodError: Exception.FuShuException: method <init>(Ljava/lang/String;)V not found
  36.         at Exception.Demo4.div(ExceptionDemo4.java:11)
  37.         at Exception.ExceptionDemo4.main(ExceptionDemo4.java:24)
复制代码

正确的不是应该是
FuShuException:除数为负数
finally
over

哪位大神给说说?

5 个回复

倒序浏览
本帖最后由 skill20 于 2014-5-22 12:15 编辑

飘过。。。
回复 使用道具 举报
复制你的代码到Eclipse中编译运行都没错啊,是不是你的文件夹设置问题,或者同一个包中的类名重复?你在代码本身没问题。
回复 使用道具 举报
我运行了没错啊
回复 使用道具 举报
renshu16 发表于 2014-5-22 12:02
复制你的代码到Eclipse中编译运行都没错啊,是不是你的文件夹设置问题,或者同一个包中的类名重复?你在代 ...

谢了   我又建立一个包    运行一遍 没错了!!!!!
回复 使用道具 举报
yes, 正常运行,没问题。


回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马