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
'Postfix'類在哪裏? –
它與PostfixDriver.java在同一個文件夾中 – thechamp
[爲什麼我在Java中得到一個NoClassDefFoundError?](https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror -in-JAVA) –