2014-07-07 36 views
0

我想過濾與文本框的tableview的數據,但我不知道爲什麼我收到錯誤javfx錯誤

控制器 我的代碼:

@FXML 
private TextField search; 
private ObservableList<person1> masterData = FXCollections.observableArrayList(); 

    @Override 
    public void initialize(URL url, ResourceBundle rb) { 




     FilteredList<person1> filteredData = new FilteredList<>(masterData, p -> true); 

       search.textProperty().addListener((observable, oldValue, newValue) -> { 
      filteredData.setPredicate(person -> { 
       // If filter text is empty, display all persons. 
       if (newValue == null || newValue.isEmpty()) { 
        return true; 
       } 

       // Compare first name and last name of every person with filter text. 
       String lowerCaseFilter = newValue.toLowerCase(); 

       if (person.getFirstName().toLowerCase().indexOf(lowerCaseFilter) != -1) { 
        return true; // Filter matches first name. 
       } 
       return false; // Does not match. 
      }); 


     }); 
        SortedList<person1> sortedData = new SortedList<>(filteredData); 

     // 4. Bind the SortedList comparator to the TableView comparator. 
     sortedData.comparatorProperty().bind(table3.comparatorProperty()); 

     // 5. Add sorted (and filtered) data to the table. 
     table3.setItems(sortedData); 

     studlist(); 

    }  


    public void studlist(){ 
    String s=(String) com2.getSelectionModel().getSelectedItem(); 
    String s1=(String) com3.getSelectionModel().getSelectedItem(); 
    String cls=""; 
    String sec=""; 
    if(!(s==null))cls="where currentclass='"+s+"'"; 
    if(!(s1==null))sec=" and currentsec='"+s1+"'"; 
     try{ 
     Class.forName("com.mysql.jdbc.Driver"); 
      Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/schoolmanagement","root","root"); 
      String sql="Select * from student_information "+s+""+s1; 
      Statement stm=(Statement) con.createStatement(); 
ResultSet rs=stm.executeQuery(sql); 
while(rs.next()){ 
table3.getItems().add(new person1(rs.getString(3), rs.getString(2))); 

} } 
     catch (ClassNotFoundException | SQLException e) { 

     } 

    } 

得到錯誤,當我想數據將在表 錯誤:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1768) 
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1651) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) 
    at javafx.event.Event.fireEvent(Event.java:204) 
    at javafx.scene.Node.fireEvent(Node.java:8175) 
    at javafx.scene.control.ComboBoxBase.valueInvalidated(ComboBoxBase.java:136) 
    at javafx.scene.control.ComboBoxBase$2.invalidated(ComboBoxBase.java:161) 
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111) 
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:145) 
    at javafx.scene.control.ComboBoxBase.setValue(ComboBoxBase.java:167) 
    at javafx.scene.control.ComboBox.updateValue(ComboBox.java:449) 
    at javafx.scene.control.ComboBox.access$300(ComboBox.java:164) 
    at javafx.scene.control.ComboBox$6.changed(ComboBox.java:434) 
    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:347) 
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) 
    at javafx.beans.property.ReadOnlyObjectWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyObjectWrapper.java:176) 
    at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:142) 
    at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112) 
    at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:145) 
    at javafx.scene.control.SelectionModel.setSelectedItem(SelectionModel.java:102) 
    at javafx.scene.control.ComboBox$ComboBoxSelectionModel$1.invalidated(ComboBox.java:481) 
    at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:135) 
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) 
    at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:176) 
    at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:142) 
    at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113) 
    at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:146) 
    at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68) 
    at javafx.scene.control.SingleSelectionModel.updateSelectedIndex(SingleSelectionModel.java:215) 
    at javafx.scene.control.SingleSelectionModel.select(SingleSelectionModel.java:149) 
    at com.sun.javafx.scene.control.skin.ComboBoxListViewSkin$9.invalidated(ComboBoxListViewSkin.java:594) 
    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:339) 
    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80) 
    at javafx.beans.property.ReadOnlyIntegerWrapper$ReadOnlyPropertyImpl.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:176) 
    at javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:142) 
    at javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:113) 
    at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:146) 
    at javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:68) 
    at javafx.scene.control.MultipleSelectionModelBase.select(MultipleSelectionModelBase.java:341) 
    at javafx.scene.control.MultipleSelectionModelBase.clearAndSelect(MultipleSelectionModelBase.java:309) 
    at com.sun.javafx.scene.control.behavior.ListCellBehavior.simpleSelect(ListCellBehavior.java:268) 
    at com.sun.javafx.scene.control.behavior.ListCellBehavior.doSelect(ListCellBehavior.java:208) 
    at com.sun.javafx.scene.control.behavior.ListCellBehavior.mousePressed(ListCellBehavior.java:127) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:95) 
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) 
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) 
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) 
    at javafx.event.Event.fireEvent(Event.java:204) 
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3746) 
    at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471) 
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695) 
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345) 
    at com.sun.glass.ui.View.handleMouseEvent(View.java:526) 
    at com.sun.glass.ui.View.notifyMouse(View.java:898) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39) 
    at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:483) 
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1763) 
    ... 91 more 
Caused by: java.lang.UnsupportedOperationException 
    at java.util.AbstractList.add(AbstractList.java:148) 
    at java.util.AbstractList.add(AbstractList.java:108) 
    at schoolmanagement2.FeesdepositeController.studlist(FeesdepositeController.java:166) 
    at schoolmanagement2.FeesdepositeController.go1(FeesdepositeController.java:203) 
    ... 101 more 

我不知道爲什麼我收到此錯誤,請幫助我。

謝謝。

+0

請發佈完整的堆棧跟蹤。 – ra2085

回答

1

您可能試圖添加到不可修改的排序列表。嘗試使用FXCollections.sort(),它對列表進行排序並保持可修改狀態。

javadoc

我不知道如果FilteredList是修改要麼,所以你仍然可能有問題。我認爲你應該添加到masterData。

編輯:我只需要5分鐘做一個測試,你不能添加到過濾或排序列表。當添加到基礎列表(masterData)時,過濾工作正常

+0

不,我想篩選tableview – user3808438

+0

但是htis錯誤'由於:java.lang.UnsupportedOperationException 在java.util.AbstractList.add(AbstractList.java:148)''是你試圖添加到列表,當你'不允許。如果您添加到基礎列表中,filteredList和sortedList應該處理過濾/排序。 – brian

+0

如何刪除此錯誤 – user3808438