当前位置: 技术问答>java相关
大家帮帮我吧...错在哪里啊?
来源: 互联网 发布时间:2015-09-22
本文导语: 编译的时候没有问题,运行的时候就不行了,从没见过的: 原来程序如下,是中缀转后缀的程序,还没有写注释呢,大家帮帮我吧: import java.util.*; import javax.swing.*; class TestCTPostFix { public static void main(String[] args) { St...
编译的时候没有问题,运行的时候就不行了,从没见过的:
原来程序如下,是中缀转后缀的程序,还没有写注释呢,大家帮帮我吧:
import java.util.*;
import javax.swing.*;
class TestCTPostFix
{
public static void main(String[] args)
{
String abc = JOptionPane.showInputDialog("Please input the prefix notation:");
ArrayList bbb = CTPostFix(abc);
System.out.println(bbb);
}
public static ArrayList CTPostFix(String InputString)
{
Object y;
StringTokenizer StreamInput = new StringTokenizer(InputString);
Stack Operator = new Stack();
ArrayList CalculatedList = new ArrayList();
while(StreamInput.hasMoreTokens())
{
Object current = StreamInput.nextElement();
if (current instanceof Double)
{
CalculatedList.add(current);
}
if (current instanceof String)
{
String currentOperator = (String)current;
if (currentOperator ==")")
for (y = Operator.pop();(String)y!="(" ;y = Operator.pop() )
{
CalculatedList.add(y);
}
else
{
for (y = Operator.pop();isp(currentOperator)>icp(currentOperator) ;y = Operator.pop() )
{
CalculatedList.add(y);
}
Operator.push(y);
Operator.push(currentOperator);
}
}
}
while(!Operator.empty())
{
y = Operator.pop();
CalculatedList.add(y);
}
return CalculatedList;
}
public static int isp(String current)
{
if (current == "+") return 2;
else if (current == "*") return 4;
else if (current == "^") return 5;
else if (current == "(") return 0;
else if (current == ")") return 6;
else return -1;
}
public static int icp(String current)
{
if (current == "+") return 1;
else if (current == "*") return 3;
else if (current == "^") return 6;
else if (current == "(") return 7;
else if (current == ")") return 0;
else return -1;
}
System.exit(1);
};
出错消息:
Exception in thread "main" java.lang.NoClassDefFoundError: TestCTpostFix (wrong
name: TestCTPostFix)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
原来程序如下,是中缀转后缀的程序,还没有写注释呢,大家帮帮我吧:
import java.util.*;
import javax.swing.*;
class TestCTPostFix
{
public static void main(String[] args)
{
String abc = JOptionPane.showInputDialog("Please input the prefix notation:");
ArrayList bbb = CTPostFix(abc);
System.out.println(bbb);
}
public static ArrayList CTPostFix(String InputString)
{
Object y;
StringTokenizer StreamInput = new StringTokenizer(InputString);
Stack Operator = new Stack();
ArrayList CalculatedList = new ArrayList();
while(StreamInput.hasMoreTokens())
{
Object current = StreamInput.nextElement();
if (current instanceof Double)
{
CalculatedList.add(current);
}
if (current instanceof String)
{
String currentOperator = (String)current;
if (currentOperator ==")")
for (y = Operator.pop();(String)y!="(" ;y = Operator.pop() )
{
CalculatedList.add(y);
}
else
{
for (y = Operator.pop();isp(currentOperator)>icp(currentOperator) ;y = Operator.pop() )
{
CalculatedList.add(y);
}
Operator.push(y);
Operator.push(currentOperator);
}
}
}
while(!Operator.empty())
{
y = Operator.pop();
CalculatedList.add(y);
}
return CalculatedList;
}
public static int isp(String current)
{
if (current == "+") return 2;
else if (current == "*") return 4;
else if (current == "^") return 5;
else if (current == "(") return 0;
else if (current == ")") return 6;
else return -1;
}
public static int icp(String current)
{
if (current == "+") return 1;
else if (current == "*") return 3;
else if (current == "^") return 6;
else if (current == "(") return 7;
else if (current == ")") return 0;
else return -1;
}
System.exit(1);
};
出错消息:
Exception in thread "main" java.lang.NoClassDefFoundError: TestCTpostFix (wrong
name: TestCTPostFix)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:509)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:246)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:262)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
|
for (y = Operator.pop();isp(currentOperator)>icp(currentOperator) ;y = Operator.pop() )
这句循环条件边界不对吧,Stack空了,你还pop,就会出EmptyStackException
这句循环条件边界不对吧,Stack空了,你还pop,就会出EmptyStackException
|
楼上几位,说的都不知道是什么。哎,不要误导人家啊。
记住文件名一定要和你的类名一致,并且要区分大小写。
建议楼主看看这里,对你有好处的。
http://www.csdn.net/expert/topic/1065/1065682.xml?temp=.4927027
记住文件名一定要和你的类名一致,并且要区分大小写。
建议楼主看看这里,对你有好处的。
http://www.csdn.net/expert/topic/1065/1065682.xml?temp=.4927027
|
TestCTpostFix
(wrong name: TestCTPostFix
注意在小写:javac TestCTPostFix(p要大写)
(wrong name: TestCTPostFix
注意在小写:javac TestCTPostFix(p要大写)
|
另外问一句,真的能编译通过吗?
语句System.exit(1);的位置好像不对吧!
语句System.exit(1);的位置好像不对吧!
|
吉大,清华,南大的数据结构上面都有原程序,
照着改就行了
照着改就行了
|
根本编译不过嘛,
System.exit(1)放在哪里的?
System.exit(1)放在哪里的?
|
editplus只是个文本开发工具,哪是编译器啊,
去掉那个system.exit(1)后就可以运行,出了applet窗口,让你输入了
但输入确定后就出现异常
去掉那个system.exit(1)后就可以运行,出了applet窗口,让你输入了
但输入确定后就出现异常
|
你的文件名TestCTpostFix 和你的类名TestCTPostFix不一致,所以出现上面的异常。注意大小写。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。