Java AWT-EventQueue-0错误 [英] Java AWT-EventQueue-0 Error

查看:81
本文介绍了Java AWT-EventQueue-0错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我调试吗,

以下代码中没有该错误 * 下面的代码内发生错误: *

   if (e.getSource().equals(btnRefresh))
        {
            PeerList.removeAllElements();
            FileList.removeAllElements();


            try {
                AllPeers=(List <String>)Services.getPeers();
            } catch (RemoteException e1) {
                // TODO Auto-generated catch block

            }

            for (String CurrentPeer:AllPeers)
            {
                System.out.println(CurrentPeer);
                PeerList.addElement(CurrentPeer);
            }
        }

错误在这里

lstPeerList.addListSelectionListener(new ListSelectionListener(){
            @Override
            public void valueChanged(ListSelectionEvent e) 
            {
                try 
                {
                    SelectedPeer=(String)lstPeerList.getSelectedValue();
                    List <String> PeerFiles=Services.getPeerFiles(SelectedPeer);
                    FileList.removeAllElements();
                    for (String CurrentFile:PeerFiles)
                    {
                        FileList.addElement(CurrentFile);
                    }
                } 
                catch (RemoteException e1) 
                {
                    // TODO Auto-generated catch block

                }
            }});

在下面的代码中,如果将变量检索为以下代码,则会发生错误:

in the code below, if am retrieving the variable as the following code, the error occurs:

SelectedPeer=(String)lstPeerList.getSelectedValue();
List <String> PeerFiles=Services.getPeerFiles(SelectedPeer);

但是如果我这样做,即不使用检索到的变量,则不会发生错误:

but if i'm doing this, i.e. not using the retrieved variable, the error doesn't occur:

SelectedPeer=(String)lstPeerList.getSelectedValue();
List <String> PeerFiles=Services.getPeerFiles("Noor");

没有错误发生,

例外:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at Server.getPeerFiles(Server.java:54)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
        at sun.rmi.transport.Transport$1.run(Transport.java:159)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:637)
        at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)
        at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)
        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142)
        at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
        at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
        at $Proxy0.getPeerFiles(Unknown Source)
        at MainForm$1.valueChanged(MainForm.java:55)
        at javax.swing.JList.fireSelectionValueChanged(JList.java:1765)
        at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1779)
        at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
        at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:147)
        at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:194)
        at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:660)
        at javax.swing.plaf.basic.BasicListUI$Handler.intervalRemoved(BasicListUI.java:2589)
        at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:161)
        at javax.swing.DefaultListModel.removeAllElements(DefaultListModel.java:385)
        at MainForm.actionPerformed(MainForm.java:223)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6267)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6032)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

推荐答案

每次选择更改时,都会调用ListSelectionListener.这可能意味着现在没有选择,lstPeerList.getSelectedValue()返回null.然后调用getPeerFiles(null),此方法似乎无法处理null参数.

The ListSelectionListener is invoked on every change of the selection. This could mean that now there is no selection, lstPeerList.getSelectedValue() returns null. Then you invoke getPeerFiles(null), and this method seems to be unable to handle null parameters.

您可以更改您的getPeerFiles方法,或者仅在所选值不是null时调用它.

You could either change your getPeerFiles method, or invoke it only if the selected value is not null.

这篇关于Java AWT-EventQueue-0错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆