2017-06-14 80 views
0

当我运行程序时,得到java.lang.NoClassDefFoundError异常。我曾在多台电脑上尝试过,但仍然出现相同的错误。我有定义的类我仍然可以找到任何人都可以帮助我的错误?没有类Def的发现错误

public class PostfixDriver { 
    public static void main(String[] args) { 
System.out.println("Testing postfix expressions with\n" + 
    "a = 2.0, b = 3.0, c = 4.0, d = 5.0\n"); 
    testPostfix("a+b"); 
testPostfix("a-b+c*d"); 
    testPostfix("(a+b)*c-d"); 
    testPostfix("a+b*(c-d)"); 
testPostfix("(a+b)/(c-d)"); 
    testPostfix("a*(b/(c-d))"); 
} // end main 

public static void testPostfix(String infixExpression) { 
String postfixExpression = Postfix.convertToPostfix(infixExpression); 
System.out.println("Infix: " + infixExpression); 
System.out.println("Postfix: " + postfixExpression); 
    System.out.println("Value: " + 
Postfix.evaluatePostfix(postfixExpression)); 
    System.out.println(); 
    } // end testPostfix 
    } // end PostfixDriver 

这是完全错误

Exception in thread "main" java.lang.NoClassDefFoundError: Postfix 
at PostfixDriver.testPostfix(PostfixDriver.java:17) 
at PostfixDriver.main(PostfixDriver.java:8) 
Caused by: java.lang.ClassNotFoundException: Postfix 
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 

它说这是从后缀来这是具有converttoPostfix阶级和一切是一样的。如果需要,我可以将它张贴。

Postfix.java

public static String convertToPostfix(String infix) { 
    ArrayStack operator = new ArrayStack(); 
    String item; 
    String postfixe; 
    Object top; 



    for(int i = 0; infix.length() >= 0; i++){ 
    item.charAt(i); 


    if (Postfix.isVariable(item.charAt(i))){ 
    postfixe.concat(item.toString());   
    } 

    else if (item.charAt(i) == '('){ 
    operator.push(item); 
    } 
    else if (item.charAt(i) == ')'){ 
    Postfix.concat(item.toString()); 
    while(!top.equals('(')){ 
     postfixe.concat(item.toString()); 
     top = operator.pop(); 
    } 
    } 
    else { 
    while(!operator.isEmpty()){ 
     top = operator.peek(); 

     if(Postfix.getPrecedence(item.charAt(i)) <= (Character)top){ 
      postfixe.concat(item); 
      operator.pop(); 
     } 
     else { 
      break; 
     } 
     operator.push(item); 

    } 
    } 


    } 

while(!operator.isEmpty()){ 
    top = operator.pop(); 
    Postfix.concat(item); 

    } 

    return postfixe; 







    } // end convertToPostfix 
+1

'Postfix'类在哪里? –

+0

它与PostfixDriver.java在同一个文件夹中 – thechamp

+1

[为什么我在Java中得到一个NoClassDefFoundError?](https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror -in-JAVA) –

回答

0

我只能猜测,但你Postfix类包含静态字段或静态初始化块?如果有错误发生,你会得到臭名昭着的NoClassDefFoundError

在那旁边,从Why am I getting a NoClassDefFoundError in Java?举:

这时候还有一类文件,你的代码依赖于它出现在编译时间,但在运行时没有发现造成的。查找构建时间和运行时类路径的差异。

但是请注意,它并不总是有类路径错误的事:

other answer,了解详情:

...关键是,一个NoClassDefFoundError的不一定类路径问题。