gpt4 book ai didi

java - 程序编译正常但因 NoClassDefFoundError 崩溃

转载 作者:行者123 更新时间:2023-12-04 06:34:58 26 4
gpt4 key购买 nike

我已经编写了五个类,简而言之,它们的目的是为 session 创建 GUI 和记录参与者。我已经构建了面板并添加了它们,FocusListeners、ActionListeners、ItemListeners。

据我所知,我在崩溃时收到的消息与我的类路径有关,但我真的不知道如何修复它。这是发生崩溃的代码(当我为面板的两个按钮添加 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)

我知道这里有很多人有很多经验,我在互联网上找不到任何帮助。

最佳答案

As for telling java where to find ConferenceHandler (and I apologize for sounding stupid - homework questions are asked by newbs) I am using Blue Jay, and all I have to do is click on the main, and the program runs. I have no idea how to do this from command line.



查看的位置在 java 的文档中。命令;例如 here .请特别注意讨论类路径和设置它的不同方式的内容。另请阅读 this page .

I realized that it was a problem with classpath, and no matter what I did, I couldn't fix it. So I took all of the original classes, and pasted them all into a new folder, and it worked like a charm.



这是一个巫毒解决方案。你真的需要了解这个问题。

为此,让我们重新审视上面的一些评论:

The stacktrace indicates otherwise. They're packageless (in other words, in the default package, if BlueJ is telling that you literally somehow). – @BalusC

I wish I knew what that meant..... - @unit



@BalusC 的意思是堆栈跟踪会告诉您它试图加载的类的全名。
    ...
Caused by: java.lang.ClassNotFoundException: ConferenceHandler
...

全名(在这种情况下)是 ConsoleHandler ...不是 some.pkg.ConsoleHandler .

不完全清楚的是为什么会发生这种情况,但我怀疑您实际上是在运行旧 .class与您正在查看的源代码不匹配的文件。你的 Voodoo 解决方案很可能通过替换旧的 .class 来“修复”这个问题。带有新内容的文件。但如果是这种情况,您需要了解您构建/部署的方式有什么问题。否则,你会一次又一次地被这种事情绊倒。

关于java - 程序编译正常但因 NoClassDefFoundError 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4982502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com