首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

奇怪的有关问题:Exception is not compatible with throws clause !会者很easy

2012-02-19 
奇怪的问题:Exception is not compatible with throws clause !会者很easy!publicclassLoadMapsimplements

奇怪的问题:Exception is not compatible with throws clause !会者很easy!
public   class   LoadMaps   implements   ContentMaps   {
....
public   MAP   getUserMap(int   localID)   throws   Exception{
//   TODO   Auto-generated   method   stub
MAP   map=new   MAP();
...        
        Oracle   newConnection=new   Oracle();
Connection   conn=   newConnection.newConnection();
try{

Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

String   sql= "select   *     from   MAP_PIN   where   LocalID= ' "+localID+ " ' ";
ResultSet   rs=stmt.executeQuery(sql);
        while(rs.next()){
        ...                 };
        rs.close();
        stmt.close();
}

finally{
if(conn!=null){conn.close();}
}

     
return   map;
}
}
结果提示:
Exception   Exception   is   not   compatible   with   throws   clause   in   ContentMaps.getUserMap(int)

不明白为什么,请高手指点!

[解决办法]
----------------------------------
try{
.............
}
finally{
if(conn!=null){conn.close();}
}
----------------------------------

不知道樓主想幹嘛,把catch丟哪去了.................
[解决办法]
呵呵,考你呢
[解决办法]
是不是你的接口ContentMaps.getUserMap(int) 在声明的时候抛出的是Exception的子类呢,我记得在实现接口时,子类抛出是异常应该是和父类的相同或是比父类的范围小才对的
[解决办法]
try{}catch(){}是一个整体有try的话一定要有catch.
[解决办法]
我这边不能调试你的程序,我记得try-finally这样结合是可以的,可以没有catch,但是没有finally的话就必须有一个以上catch.
根据提示应该抛出的并不是Exception或者其子类,你改下你的抛出范围,改成如下:
public MAP getUserMap(int localID)throws Throwable
这样应该就不会错了.我不能调试你的程序,还得麻烦楼主自己调试了.
[解决办法]
public MAP getUserMap(int localID) throws Exception{


查查ContentMaps里有没有throws Exception

热点排行
Bad Request.