运行方法时出现 NoClassDefError

发布于 2024-11-16 07:25:10 字数 2001 浏览 4 评论 0原文

当我尝试运行以下代码时,会弹出以下错误,我不知道为什么,它实际上在 10 分钟前就起作用了,

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(newKeyEventPostProcessor() {
        public boolean postProcessKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                if(e.isControlDown() && e.getKeyCode() == KeyEvent.VK_P){
                    printSinglePage();
                    e.consume();                           
                }
                if(e.isControlDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.VK_P){
                    printAll();
                    e.consume();                           
                }
            }
            return true;
        }
    });

    public void printSinglePage(){
        if(tab.getSelectedComponent() instanceof DuctReport)
            PrintUtilities.printComponent(tab.getSelectedComponent(), DuctReport.PRINT_SIZE);
        else if(tab.getSelectedComponent() instanceof Vandy)
            PrintUtilities.printComponent(tab.getSelectedComponent(), Vandy.PRINT_SIZE);
        else
            PrintUtilities.printComponent(tab.getSelectedComponent(), .8);
    }

    public void printAll(){
        for(int i = 0; i < tab.getTabCount(); i ++){
            if(tab.getComponent(i) instanceof DuctReport)
                PrintUtilities.printComponent(tab.getComponent(i), DuctReport.PRINT_SIZE);
            else if(tab.getComponent(i) instanceof Vandy)
                PrintUtilities.printComponent(tab.getComponent(i), Vandy.PRINT_SIZE);
            else
                PrintUtilities.printComponent(tab.getComponent(i), .8);               
        }  
    }

这是错误:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: PrintUtilities
    at Main.printSinglePage(Main.java:282)
    at Main.menPrintAllActionPerformed(Main.java:221)
    at Main.access$600(Main.java:24)
    at Main$8.actionPerformed(Main.java:148)

When i try to run the following code the following error pops up and I do not know why, it worked literally 10 minutes ago

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(newKeyEventPostProcessor() {
        public boolean postProcessKeyEvent(KeyEvent e) {
            if (e.getID() == KeyEvent.KEY_PRESSED) {
                if(e.isControlDown() && e.getKeyCode() == KeyEvent.VK_P){
                    printSinglePage();
                    e.consume();                           
                }
                if(e.isControlDown() && e.isAltDown() && e.getKeyCode() == KeyEvent.VK_P){
                    printAll();
                    e.consume();                           
                }
            }
            return true;
        }
    });

    public void printSinglePage(){
        if(tab.getSelectedComponent() instanceof DuctReport)
            PrintUtilities.printComponent(tab.getSelectedComponent(), DuctReport.PRINT_SIZE);
        else if(tab.getSelectedComponent() instanceof Vandy)
            PrintUtilities.printComponent(tab.getSelectedComponent(), Vandy.PRINT_SIZE);
        else
            PrintUtilities.printComponent(tab.getSelectedComponent(), .8);
    }

    public void printAll(){
        for(int i = 0; i < tab.getTabCount(); i ++){
            if(tab.getComponent(i) instanceof DuctReport)
                PrintUtilities.printComponent(tab.getComponent(i), DuctReport.PRINT_SIZE);
            else if(tab.getComponent(i) instanceof Vandy)
                PrintUtilities.printComponent(tab.getComponent(i), Vandy.PRINT_SIZE);
            else
                PrintUtilities.printComponent(tab.getComponent(i), .8);               
        }  
    }

here is the error:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: PrintUtilities
    at Main.printSinglePage(Main.java:282)
    at Main.menPrintAllActionPerformed(Main.java:221)
    at Main.access$600(Main.java:24)
    at Main$8.actionPerformed(Main.java:148)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

辞慾 2024-11-23 07:25:10

通常,NoClassDefFoundError 是类加载器或类路径问题的结果。检查 jar 是否没有被重命名或移动,您的运行脚本是否正确,诸如此类。代码可能没问题,重要的是环境。

如果您仍然无法解决此问题,请考虑发布有关您的框架、IDE 以及应用程序启动方式的更多详细信息。

Typically, a NoClassDefFoundError is the result of classloader or classpath issues. Check that a jar hasn't gotten renamed or moved, that your run script is correct, stuff like that. The code's probably fine, it's the environment.

Please consider posting more details of your framework, IDE, and how the apps started if you're still unable to fix this.

自我难过 2024-11-23 07:25:10

我在使用 NetBeans 时遇到过类似的奇怪错误。我经常进行“清理和构建”来修复它。有时需要关闭 NetBeans 并清除 NB 缓存。

I've seen weird errors like this when working in NetBeans. I often do a "Clean and Build" to fix it. Sometimes is is necessary to shut down NetBeans and clear the NB cache.

失眠症患者 2024-11-23 07:25:10

这是一个环境问题,通常清理和重建项目可以解决问题。

It's an environment problem, usually cleaning and rebuilding the project solves the problem.

风启觞 2024-11-23 07:25:10

我已经犯过几次这个错误了。对我来说导致它的主要原因是初始化期间的空指针异常。第二件事是在初始化时使用静态变量,显然你不能直接使用任何静态数组(并且尝试使用导致这种情况的方法)。

要点:检查你的构造函数并确保那里没有任何异常,这就是我的原因。

I've had this error a few times. The main thing that causes it for me is a nullpointerexception during initialization. The second thing is working with static variables when initializing, apparently you can't work with any static array directly (and trying to use methods led to this).

Main point: Check your constructor and make sure there aren't any exceptions there, that's what causes it for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文