can someone help me to debug this,
Edit 1: the error is not in the code below *Error occurs within the code below:*
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);
}
}
Edit 1: Error is here
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");
No error occurs,
Exception:
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.开发者_Go百科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)
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.
You could either change your getPeerFiles
method, or invoke it only if the selected value is not null
.
Whatever is on line 54
at Server.getPeerFiles(Server.java:54)
Is null, so post line 54
Edit:
Possible things that could be null:
e, btnRefresh, PeerList, FileList, Services
Whatever one of those that is on line 54 is your cause.
(Sorry didn't know to add it to my original post)
精彩评论