我写了五个类,简而言之,它们用于创建GUI并记录会议的参与者。我已经构建了面板并添加了它们,FocusListeners,ActionListeners和ItemListeners。程序编译正常,但与NoClassDefFoundError崩溃
从我能收集到的信息来看,崩溃与我的Classpath有关,但我不知道如何解决它。这里就是碰撞发生的代码(这是当我添加的ActionListeners这两个按钮为我的面板:
private void buildButtonPanel()
{
//create the buttonpanel
buttonPanel = new JPanel(new FlowLayout());
//create the buttons
calculate = new JButton("Calculate Charges");
clear = new JButton ("Clear");
//add listeners to the buttons
ConferenceHandler handler = new ConferenceHandler(this);
calculate.addActionListener(handler); //crash occurs on this line
clear.addActionListener(handler);
//create a text area
JTextArea textArea = new JTextArea(5,30);
textArea.setLineWrap(true); textArea.setWrapStyleWord(true);
//add a scrollbar to the textarea
JScrollPane scroll = new JScrollPane (textArea);
//add everything to the buttonpanel
buttonPanel.add(calculate); buttonPanel.add(clear); buttonPanel.add(scroll);
}
坠毁的消息,我得到:
java.lang.NoClassDefFoundError: ConferenceHandler
at ConferenceGUI.buildButtonPanel(ConferenceGUI.java:63)
at ConferenceGUI.<init>(ConferenceGUI.java:33)
at IsItWorking.<init>(IsItWorking.java:16)
at IsItWorking.main(IsItWorking.java:28)
Caused by: java.lang.ClassNotFoundException: ConferenceHandler
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at ConferenceGUI.buildButtonPanel(ConferenceGUI.java:63)
at ConferenceGUI.<init>(ConferenceGUI.java:33)
at IsItWorking.<init>(IsItWorking.java:16)
at IsItWorking.main(IsItWorking.java:28)
at __SHELL0.run(__SHELL0.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at bluej.runtime.ExecServer$3.run(ExecServer.java:774)
我知道有一个很多人在这里有很多的经验,我无法找到这一个在interwebs任何帮助
你用`-classpath`参数告诉java在哪里可以找到`ConferenceHandler`吗?像`java -classpath/path/to/directory/with/compiled/ConferenceHandler程序` – birryree 2011-02-13 04:58:28
对于作业标记来说还不够公平,而且人们总是添加它。至于告诉java在哪里可以找到ConferenceHandler(并且我为听起来很愚蠢而道歉 - homebs问题是由newbs提出的)我正在使用Blue Jay,我所要做的就是点击main,然后程序运行。我不知道如何从命令行执行此操作。 – unit 2011-02-13 05:02:07