그레이딩 시스템 용 스윙 GUI에서 작업하고 있습니다. 어떤 이유로, 내 삭제 Jbutton
뿐만 아니라 모델을 지우는 메서드는 호출 할 때 NPE를 반환하기 시작했습니다. 그들은 이전에 작업 중이었고 디버거를 사용하여 색인이 정확하다는 것을 알았습니다. 작동하지 않는 이유를 찾을 수 없습니다.DefaulListModel의 NullPointerException
이제 모델에 추가 할 수 있지만 어떤 이유로 요소를 지우거나 제거 할 수 없습니다.
편집 : 방금 테스트를했는데 문제없이 작동합니다.이 코드는 문제가되지 않습니다.
DefaultListModel<Student> model; //List model in View class
private void handleDeleteButton(){ //Controller class method to handle delete button
int indexToDelete = sv.listSelectedIndex();
if(indexToDelete >= 0){
model.remove(indexToDelete); //remove Student object from DefaultListModel
}
}
public int listSelectedIndex(){ //method in the View class to return the selected list index
return studentList.getMinSelectionIndex();
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gradingsystem.SView.setFields(SView.java:136)
at gradingsystem.SController.valueChanged(SController.java:181)
at javax.swing.JList.fireSelectionValueChanged(JList.java:1798)
at javax.swing.JList$ListSelectionHandler.valueChanged(JList.java:1812)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:677)
at javax.swing.plaf.basic.BasicListUI$Handler.intervalRemoved(BasicListUI.java:2601)
at javax.swing.AbstractListModel.fireIntervalRemoved(AbstractListModel.java:179)
at javax.swing.DefaultListModel.remove(DefaultListModel.java:498)
at gradingsystem.SController.handleDeleteButton(SController.java:63)
at gradingsystem.SController.actionPerformed(SController.java:96)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:713)
at java.awt.EventQueue.access$000(EventQueue.java:104)
at java.awt.EventQueue$3.run(EventQueue.java:672)
at java.awt.EventQueue$3.run(EventQueue.java:670)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:686)
at java.awt.EventQueue$4.run(EventQueue.java:684)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:683)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
stacktrace를 게시하여 자세한 정보를 얻을 수 있습니까? – bvidal