0

My application has a button, that when clicked, opens another JFrame class (ClassB) to display a message. It worked fine with the following code:

private void btnClickActionPerformed(java.awt.event.ActionEvent evt)
{
    ClassB cb = new ClassB();
    cb.setVisible(true);
}

But I decided to do away with that JFrame class and display the message on the current JFrame. The problem is when I click on the btnNext button, it still tries to open ClassB even though the code has been deleted AND the class itself has been deleted.

I have gone through every line of code and there is no trace of ClassB existing. There's no reason for the application to look for ClassB yet it does.

Why is it doing this and what can I do to fix this?

Here is the exception error that comes up in the stack trace:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: myPackage/ClassB
    at myPackage.MainFrame.btnNextActionPerformed(MainFrame.java:6867)
    at myPackage.MainFrame.access$200(MainFrame.java:12)
    at myPackage.MainFrame$3.actionPerformed(MainFrame.java:8383)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6535)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6300)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4891)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2750)
    at java.awt.Component.dispatchEvent(Component.java:4713)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: myPackage.ClassB

Bit of a side note:

Initially I just commented the code to open ClassB out and ClassB still opened when the button was clicked

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Osiris93
  • 296
  • 2
  • 18
  • 3
    Recompile the class containing the code shown. – Andy Turner Jul 11 '16 at 11:41
  • 1
    Please try cleaning and rebuilding the project, using Run->Clean and build project in the Netbeans IDE. – nanofarad Jul 11 '16 at 11:41
  • 1
    This might be silly but, you did actually rebuild, did you? – Dylan Meeus Jul 11 '16 at 11:41
  • I've also tried recompiling and doing a clean and build, the problem persists – Osiris93 Jul 11 '16 at 11:43
  • it might be that you added two action listeners for same button that opens classB and you commented only one. – SomeDude Jul 11 '16 at 11:51
  • 1
    *"the problem persists"* It throws an exception? Copy/paste the stack trace here. See also [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) – Andrew Thompson Jul 11 '16 at 11:55
  • 1
    And a tip: Add @AndyTurner (or whoever, the `@` is important) to *notify* the person of a new comment. Also more generally, the '2nd' frame should never have been a frame. See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jul 11 '16 at 11:59
  • @AndrewThompson I added the stack trace as an edit in my question – Osiris93 Jul 11 '16 at 12:03
  • `at myPackage.MainFrame.btnNextActionPerformed(MainFrame.java:6867)` Ummm.. OK. Did you read the "what is a stack trace.." link? – Andrew Thompson Jul 11 '16 at 12:14
  • @AndrewThompson Yes I did, it just took me to the following line of code: `mainPanel.add(lblEnterName);`. A JLabel with no functionality assigned to it, which makes this matter even more puzzling to me. And yes I did read the link – Osiris93 Jul 11 '16 at 12:19
  • Then it sounds as though the very first suggestion by @AndyTurner was correct. For Netbeans, it is `Shift+F11` to `Clean and Build Project (.. project name..)` – Andrew Thompson Jul 11 '16 at 12:27
  • @AndrewThompson But like I said, I have tried that and it didn't fix the problem. The application is still looking for `ClassB` – Osiris93 Jul 11 '16 at 12:29
  • @Osiris93 then you've still got references in classes your code depends on. – Andy Turner Jul 11 '16 at 12:31
  • @AndyTurner Any suggestions as to where else I can look? Because I have gone through all my code and cannot find any references. I even tried searching references with the "Find" function and nothing was found. – Osiris93 Jul 11 '16 at 12:34
  • @Osiris93 no idea, sorry. But you *must* have a reference to it somewhere, since it won't be loaded for no reason. One particularly sticky place you might not be able to find easily using "find" is any code which loads classes reflectively. – Andy Turner Jul 11 '16 at 12:38
  • 1
    *"..where else I can look?"* Unless your enitre IDE is SNAFU - line 6867 of `MainFrame.java` - just like the stack trace identifies. – Andrew Thompson Jul 11 '16 at 12:38
  • BTW - been meaning to point out.. `MainFrame.java` is appraently ***longer*** than 6867 lines of code. By the time you get to 1000-1500 lines of code in a single class, it is a sure sign it is doing too much & needs to be refactored into separate classes! That will help save you from situations like this.. – Andrew Thompson Jul 11 '16 at 12:41
  • @AndrewThompson Do you know of any good links to help me with that as calling (and working with) objects from other classes is one of my weak points in Java – Osiris93 Jul 11 '16 at 13:05
  • @Osiris93 Nope. I'm no 'design' expert myself. What I wrote was picked up from people who *are* design experts - on sites like this. – Andrew Thompson Jul 11 '16 at 13:08

0 Answers0