Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWT-EventQueue-0" java.lang.NullPointerException

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
Any idea why _mgr is null when I attempt to call openConnection()? It gets instantialed in the GUI constructor?

Code:
public class UTFSimulatorGUI extends JFrame implements ActionListener {

    UTFConnectionManager _mgr = null;
        
    public UTFSimulatorGUI() {
        UTFConnectionManager _mgr = new UTFConnectionManager();
    }
    
    private void openConnection(){
        System.out.println("Made it here");
	_mgr.openConnection();
    }
    
    public void actionPerformed(ActionEvent event) {
        Object source = event.getSource();
        if (source == _openSocket) {
            openConnection();
        }
    }
    

    private class UTFConnectionManager {
        public UTFConnectionManager() {
            super();
        }
        
        private void openConnection() {
            // I NEVER GET HERE
	    updateGUIStatus("OPENING CONNECTION");
        }
        
}

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.gtech.simulator.UTFSimulatorGUI.openConnection(UTFSimulatorGUI.java:60)
at com.gtech.simulator.UTFSimulatorGUI.actionPerformed(UTFSimulatorGUI.java:227)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
 
perfect example why one should not code at 11pm while after working all day. sorry for the stupidity.

fix...
Code:
 UTFConnectionManager _mgr;
        
    public UTFSimulatorGUI() {
     _mgr = new UTFConnectionManager();

i dont know how i missed that.
 
I don't think it's stupid, I'd include that error in the hardest level to find.

I've been stumped for hours with these kind of errors, usually until someone that has no idea of what are you doing comes and says: "What are you doing?"

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top