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

try catch话语

2011-12-07 
try catch语句class Test{int devide(int x,int y){int reslut0reslutx/yreturn x/y}}class TestExce

try catch语句
class Test
{

int devide(int x,int y)
{
int reslut=0;
reslut=x/y;
return x/y;
}
}
class TestException
{
public static void main(String [] args)
{
try
{
int reslut=new Test().devide(3,1);
System.out.println(reslut);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("programe is running here,that is nomare");

}
}

--------------------配置: <默认>--------------------
F:\4\TestException.java:20: incompatible types
found : Exception
required: java.lang.Throwable
  catch(Exception e)
  ^
F:\4\TestException.java:22: cannot resolve symbol
symbol : method getMessage ()
location: class Exception
  System.out.println(e.getMessage());
  ^
2 errors

处理已完成。



[解决办法]
你的Exception有问题
重装下JDK看看
[解决办法]
估计是你在这个目录下(或者说当前包下)自己写了个名叫Exception的类。
自己写的类,名字最好不要个java.lang包底下的类重名,否则出了错,你都不好查。除非你确实知道自己在做什么。
[解决办法]
我测了下,你的程序没有问题,
还是重新安装jdk吧,省事方便


热点排行