2017-06-14 20 views
0

私はプログラムを実行するとjava.lang.NoClassDefFoundError例外が発生しました。私は複数のコンピュータでそれを試しても、同じエラーが発生します。私は定義されたクラスを持っている私はまだ誰かが私を助けることができるエラーを見つけることができますか?クラス定義が見つかりませんでした。エラー

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 

converttoPostfixを持っており、必要に応じて同じであることすべてが..私はそれを投稿することができますクラスであることはPostfixのから来ていると言っている完全なエラー

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) 

です。

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が、必ずしもではありませんクラスパスの問題

関連する問題