简体   繁体   中英

NoClassDefError when running a method

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)

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.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM