线程“AWT-EventQueue-0”运行时错误中的异常

时间:2014-08-20 06:28:29

标签: java exception awt runtime-error actionlistener

所以我编写了这个程序,此刻,所有的按钮都按照我的要求去做,但是出现了很多运行时错误。以下是整个文字的链接:http://pastie.org/9488033#6,16-17

deleteClient.addActionListener(new ActionListener(){

            @Override
        public void actionPerformed(ActionEvent arg0){
                //panel info
                JPanel panel2 = new JPanel();
                panel2.setLayout(new GridBagLayout());
                GridBagConstraints d = new GridBagConstraints();
                d.fill = GridBagConstraints.HORIZONTAL;

                //frame
                JFrame frame2 = new JFrame("Remove Client");

                //text area for waiting number
                final JTextArea waitingNumberArea = new JTextArea("Enter clients waiting number you wish to remove");
                JScrollPane scroll4 = new JScrollPane(waitingNumberArea);
                d.ipadx = 60;
                d.ipady = 20;
                d.gridwidth = 1;
                d.gridx = 0;
                d.gridy = 0;
                panel2.add(scroll4, d);

                //text area for name
                final JTextArea nameTextArea = new JTextArea("Enter client name");
                JScrollPane scroll3 = new JScrollPane(nameTextArea);
                d.ipadx = 60;
                d.ipady = 20;
                d.gridwidth = 1;
                d.gridx = 0;
                d.gridy = 1;
                panel2.add(scroll3, d);

                //text area for surname
                final JTextArea surnameTextArea = new JTextArea("Enter client surname");
                JScrollPane scroll2 = new JScrollPane(surnameTextArea);
                d.ipadx = 60;
                d.ipady = 20;
                d.gridwidth = 1;
                d.gridx = 0;
                d.gridy = 2;
                panel2.add(scroll2, d);

                //text area for number
                final JTextArea numberTextArea = new JTextArea("Enter client number");
                JScrollPane scroll1 = new JScrollPane(numberTextArea);
                d.ipadx = 60;
                d.ipady = 20;
                d.gridwidth = 1;
                d.gridx = 0;
                d.gridy = 3;
                panel2.add(scroll1, d);

                //button to add client
                JButton removeClient = new JButton("Remove Client");
                d.ipadx = 0;
                d.ipady = 90;
                d.gridwidth = 1;
                d.gridheight = 4;
                d.gridx = 1;
                d.gridy = 0;
                panel2.add(removeClient, d);

                //frame settings
                frame2.setVisible(true);
                frame2.setLocationRelativeTo(null);
                frame2.add(panel2);
                frame2.pack();
                frame2.setResizable(false);

                removeClient.addActionListener(new ActionListener(){

            @Override
        public void actionPerformed(ActionEvent arg0){

                final String waitingNumber = waitingNumberArea.getText();
                final String clientName = nameTextArea.getText();
                final String clientSurname = surnameTextArea.getText();
                final String clientNumber = numberTextArea.getText();
                int rows = 20;
                int columns = 4;
                int g;
                for (int r = 0; r < rows ; r++ )
                {
                        if (clientsArray[r][0].equals (waitingNumber))

                                            for (int i = 0; i < 4 ; i++ )
                                            {
                                                tableModel.setValueAt("", r, i);
                                                clientsArray[r][i] = ("0"); 
                                            }                       

                }

            }


                });
            }
        });

一切正常,但会出现这些运行时错误

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at jTableTest$3$1.actionPerformed(jTableTest.java:390)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20
22)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2346)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:402)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:252)
        at java.awt.Component.processMouseEvent(Component.java:6527)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
        at java.awt.Component.processEvent(Component.java:6292)
        at java.awt.Container.processEvent(Container.java:2234)
        at java.awt.Component.dispatchEventImpl(Component.java:4883)
        at java.awt.Container.dispatchEventImpl(Container.java:2292)
        at java.awt.Component.dispatchEvent(Component.java:4705)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
        at java.awt.Container.dispatchEventImpl(Container.java:2278)
        at java.awt.Window.dispatchEventImpl(Window.java:2739)
        at java.awt.Component.dispatchEvent(Component.java:4705)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
        at java.awt.EventQueue.access$400(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:697)
        at java.awt.EventQueue$3.run(EventQueue.java:691)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:75)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:86)
        at java.awt.EventQueue$4.run(EventQueue.java:719)
        at java.awt.EventQueue$4.run(EventQueue.java:717)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDo
main.java:75)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:201)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.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)

0 个答案:

没有答案