用Jcreator编译如下代码:(代码没有错误)
1 import java.util.*; 2 3 public class aa 4 { 5 public static double trianglearea(double a,double b,double c) 6 throws NotTriAngleException,NegativeArgementsException{ 7 //判定a,b,c是否全为正数 8 if(a < 0 || b < 0 || c < 0) 9 throw new NegativeArgementsException(); 10 //判定a,b,c是否能构成三角形 11 if(a+b<=c || b+c<=a || a+c<=b) 12 throw new NotTriAngleException(); 13 14 //计算三角形面积 15 double m = (a+b+c)/2.0; 16 double s; 17 s = Math.sqrt(m*(m-a)*(m-b)*(m-c)); 18 return s; 19 20 } 21 22 public static void main(String[] args) 23 { 24 double a,b,c; 25 int N; 26 Scanner sc= new Scanner(System.in); 27 N = sc.nextInt(); 28 for(int i=0;i<N;i++){ 29 try{ 30 a=sc.nextDouble(); 31 b=sc.nextDouble(); 32 c=sc.nextDouble(); 33 System.out.printf("%.2f\n",aa.trianglearea(a,b,c)); 34 }catch(InputMismatchException q){ 35 return ; 36 } 37 catch(NotTriAngleException q){ 38 39 } 40 catch(NegativeArgementsException q){ 41 42 } 43 } 44 } 45 } 46 47 class NotTriAngleException extends Exception 48 { 49 NotTriAngleException() 50 { 51 System.out.println("Not TriAngle"); 52 } 53 } 54 55 class NegativeArgementsException extends Exception 56 { 57 NegativeArgementsException() 58 { 59 System.out.println("Negative Argements"); 60 } 61 }
编译时出现如下错误:
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 java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(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)
慕森王
互换的青春
倚天杖
相关分类