Results 1 to 4 of 4
  1. #1
    cucucur is offline Member
    Join Date
    Apr 2011
    Posts
    20
    Rep Power
    0

    Default JComboxBox events

    hi!! I don't know how to solve my problem.

    I have 3 JComboxBox, the second one depends on the first value, and the third one depends on the second one.

    The problem is that when I change the first one, and I made a mistake, when I change it again I have an Exception:

    PHP Code:
    public class listenerName implements ActionListener {
    	public void actionPerformed (ActionEvent e) {
    		select surname from user where name = "name.getSelectedItem.toString()"
           }
    }
    
    public class listenerSurname implements ActionListener {
    	public void actionPerformed (ActionEvent e) {
    		select age from user where surname = "surname.getSelectedItem.toString()"
           }
    }
    how can I solve it??

    Thanks!!!

  2. #2
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default

    could you describe the exception message plz

  3. #3
    cucucur is offline Member
    Join Date
    Apr 2011
    Posts
    20
    Rep Power
    0

    Default

    java.lang.NullPointerException
    at alquilar$listenerSurname.actionPerformed(alquilar. java:188)
    at javax.swing.JComboBox.fireActionEvent(Unknown Source)
    at javax.swing.JComboBox.contentsChanged(Unknown Source)
    at javax.swing.JComboBox.intervalRemoved(Unknown Source)
    at javax.swing.AbstractListModel.fireIntervalRemoved( Unknown Source)
    at javax.swing.DefaultComboBoxModel.removeAllElements (Unknown Source)
    at javax.swing.JComboBox.removeAllItems(Unknown Source)
    at alquilar$listenerName.actionPerformed(alquilar.jav a:162)
    at javax.swing.JComboBox.fireActionEvent(Unknown Source)
    at javax.swing.JComboBox.setSelectedItem(Unknown Source)
    at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mou seReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMo useEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    PHP Code:
    com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND b.clientID = (SELECT clientID FROM parking p, locks l WHERE p.parkingID = l.' at line 1
    at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:936)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2985)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:16 31)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java :1723)
    at com.mysql.jdbc.Connection.execSQL(Connection.java: 3277)
    at com.mysql.jdbc.Connection.execSQL(Connection.java: 3206)
    at com.mysql.jdbc.Statement.executeQuery(Statement.ja va:1232)
    at mysqlRemoto.returnIbuttonCorrect(mysqlRemoto.java: 135)
    at alquilar$listenerCandado.actionPerformed(alquilar. java:188)
    at javax.swing.JComboBox.fireActionEvent(Unknown Source)
    at javax.swing.JComboBox.contentsChanged(Unknown Source)
    at javax.swing.AbstractListModel.fireContentsChanged( Unknown Source)
    at javax.swing.DefaultComboBoxModel.setSelectedItem(U nknown Source)
    at javax.swing.DefaultComboBoxModel.addElement(Unknow n Source)
    at javax.swing.JComboBox.addItem(Unknown Source)
    at alquilar$listenerRFID.actionPerformed(alquilar.jav a:163)
    at javax.swing.JComboBox.fireActionEvent(Unknown Source)
    at javax.swing.JComboBox.setSelectedItem(Unknown Source)
    at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup$Handler.mou seReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at javax.swing.plaf.basic.BasicComboPopup$1.processMo useEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.awt.EventQueue$2.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectio nPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    You only needed the first two lines of your error code.

    Anyway, I don't know how you've tried to achieve this, but this way should work:

    //add action listeners to the combo boxes when the form is loaded
    Java Code:
    private void initComponents {
        //items displayed in jComboBox1
        String[] someArray = new String[] {"Item 1", "Item 2", "Item 3"};
        //items displayed in jComboBox2
        String[][] some2Darray = new String[][] {
            {"Item 1: subItem 1", "Item 1: subItem 2"},
            {"Item 2: subItem 1", "Item 2: subItem 2"},
            {"Item 3: subItem 1", "Item 3: subItem 2"}
        };
        //initialise combo boxes
        jComboBox1 = new JComboBox();
        jComboBox2 = new JComboBox();
        jComboBox3 = new JComboBox();
        jComboBox1.setModel(new DefaultComboBoxModel(someArray));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                int selectedIndex = jComboBox1.getSelectedIndex();
                jComboBox2.setModel(new DefaultComboBoxModel(some2Darray[selectedIndex]));
            }
        });
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                int selectedIndex = jComboBox2.getSelectedIndex();
                jComboBox3.setModel(...);
            }
        });
    }

Similar Threads

  1. JComboxBox events
    By cucucur in forum Advanced Java
    Replies: 5
    Last Post: 04-19-2011, 12:55 PM
  2. Key Events
    By rdjava in forum Java Gaming
    Replies: 0
    Last Post: 04-15-2011, 09:02 AM
  3. typed events vs untyped events.
    By Drun in forum SWT / JFace
    Replies: 0
    Last Post: 11-23-2009, 01:22 PM
  4. Need Help with events
    By Gatts79 in forum AWT / Swing
    Replies: 3
    Last Post: 09-23-2008, 04:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •