java: 用JCeator编译器,编译出现问题怎么解决?
用Jcreator编译如下代码:(代码没有错误)程序代码:
import java.util.*; import java.lang.*; public class aa { public static double trianglearea(double a,double b,double c) throws NotTriAngleException,NegativeArgementsException { //判定a,b,c是否全为正数 if(a < 0 || b < 0 || c < 0) throw new NegativeArgementsException(); //判定a,b,c是否能构成三角形 if(a+b<=c || b+c<=a || a+c<=b) throw new NotTriAngleException(); //计算三角形面积 double m = (a+b+c)/2.0; double s; s = Math.sqrt(m*(m-a)*(m-b)*(m-c)); return s; } public static void main(String[] args) { double a,b,c; int N; Scanner sc= new Scanner(System.in); N = sc.nextInt(); for(int i=0;i<N;i++){ try{ a=sc.nextDouble(); b=sc.nextDouble(); c=sc.nextDouble(); System.out.printf("%.2f\n",aa.trianglearea(a,b,c)); }catch(InputMismatchException q){ break; } catch(NotTriAngleException q){ } catch(NegativeArgementsException e){ } } } } class NotTriAngleException extends Exception { NotTriAngleException() { System.out.println("Not TriAngle"); } } class NegativeArgementsException extends Exception { NegativeArgementsException() { System.out.println("Negative Argements"); } }
编译时出现如下错误:
F:\java学习\aa.java:6: 不兼容的类型
找到: NotTriAngleException
需要: java.lang.Throwable
throws NotTriAngleException,NegativeArgementsException{
^
F:\java学习\aa.java:6: 不兼容的类型
找到: NegativeArgementsException
需要: java.lang.Throwable
throws NotTriAngleException,NegativeArgementsException{
^
F:\java学习\aa.java:9: 不兼容的类型
找到: NegativeArgementsException
需要: java.lang.Throwable
throw new NegativeArgementsException();
^
F:\java学习\aa.java:12: 不兼容的类型
找到: NotTriAngleException
需要: java.lang.Throwable
throw new NotTriAngleException();
^
F:\java学习\aa.java:37: 不兼容的类型
找到: NotTriAngleException
需要: java.lang.Throwable
catch(NotTriAngleException q){
^
F:\java学习\aa.java:40: 不兼容的类型
找到: NegativeArgementsException
需要: java.lang.Throwable
catch(NegativeArgementsException q){
^
6 错误
Process completed.
运行时错误有:
java.lang.NoClassDefFoundError: aa
Caused by: java.lang.ClassNotFoundException: aa
at (URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at (URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: aa. Program will exit.
Exception in thread "main"
Process completed.
请求高手解决,代码没有问题,不知道是编译器,还是环境问题。
求解决方法。(用的编译器为JCreator)