Java 找不到类定义错误

Java 找不到类定义错误,java,data-structures,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.

当我运行程序时,我得到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,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
public静态字符串convertToPostfix(字符串中缀){
ArrayStack运算符=新建ArrayStack();
字符串项;
字符串后固定;
物体顶部;
对于(int i=0;infix.length()>=0;i++){
项目.特征(i);
if(Postfix.isVariable(item.charAt(i))){
postfix.concat(item.toString());
}
如果(项目特征(i)='('){
操作员推送(项目);
}
如果(项目.字符(i)=')'){
Postfix.concat(item.toString());
而(!top.equals('(')){
postfix.concat(item.toString());
top=operator.pop();
}
}
否则{
而(!operator.isEmpty()){
top=operator.peek();

如果(Postfix.getpreference(item.charAt(i))我只能猜测,但是您的
Postfix
类是否包含静态字段或静态初始化块?如果在那里抛出错误,您将得到臭名昭著的
NoClassDefFoundError

除此之外,引用:

这是由于存在代码所依赖的类文件,并且该类文件在编译时存在,但在运行时找不到。请查找生成时类路径和运行时类路径中的差异

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

有关更多详细信息,请参阅:

…关键是,NoClassDefFoundError不一定是类路径问题


Postfix
类在哪里?它与Postfix驱动程序位于同一文件夹中。java可能重复