没有发现Class Def错误

时间:2017-06-14 21:13:44

标签: java data-structures

我在运行程序时遇到了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

这是完整的错误

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,它是具有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 个答案:

答案 0 :(得分:0)

我只能猜测,但你的Postfix类是否包含静态字段或静态初始化块?如果在那里抛出错误,你会得到臭名昭着的NoClassDefFoundError

除此之外,引用Why am I getting a NoClassDefFoundError in Java?

  

当您的代码所依赖的类文件存在于编译时但在运行时未找到时,会导致这种情况。查找构建时和运行时类路径的差异。

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

有关详细信息,请参阅other answer

  

......重点是,NoClassDefFoundError不一定是类路径问题。

相关问题