错误:在TableView列列表中检测到重复的TableColumns

时间:2018-05-24 04:42:27

标签: java javafx

我正在设置此函数的tablecolumns值,即。,setTable(按下一个按钮时调用)

  

实际上有两个表,但是这个表只为第一个表设置tablecolumns的值

public class abc {   
   public void setTable(ActionEvent event)throws IOException{
        //i am getting table controller because tableview is in another scene.
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("table_scene.fxml"));
        fxmlLoader.load();
        table_scene controller = fxmlLoader.getController();
        controller.C1.setCellValueFactory(new PropertyValueFactory<>("Classs"));
        controller.N1.setCellValueFactory(new PropertyValueFactory<>("Name"));
        controller.S1.setCellValueFactory(new PropertyValueFactory<>("Sec"));
        controller.table1.getColumns().addAll(controller.C1,controller.N1,controller.S1);
        controller.table1.setItems(getDetails());

public ObservableList<TableItems> getDetails() {
  ObservableList<TableItems> list = FXCollections.observableArrayList();

        //Here are jdbc codes for retreiving the value of n1,c1,v1 and so on.
        //Tell me if i should add this code

        list.add(new TableItems(n1,c1,se1));
        list.add(new TableItems(n2,c2,se2));
        list.add(new TableItems(n3,c3,se3));
        list.add(new TableItems(n4,c4,se4));
       return list;
    }
}

这是表格所在的table_scene.fxml的控制器。

public class table_scene {
    @FXML
    TableView<TableItems> table1;
    @FXML
    TableView<TableItems> table2;
    @FXML
    TableColumn<TableItems,String> N1;
    @FXML
    TableColumn<TableItems,Integer> C1;
    @FXML
    TableColumn<TableItems,String> S1;
    @FXML
    TableColumn<TableItems,String> N2;
    @FXML
    TableColumn<TableItems,Integer> C2;
    @FXML
    TableColumn<TableItems,String> V2;
}

这是从另一个场景调用的另一个函数,我在另一个tableview的表列中设置值。 有两个表。此函数将值设置为另一个表的tablecolumn。

   public class abc2 {   
   public void setTable(ActionEvent event)throws IOException{
        //i am getting table controller because tableview is in another scene.
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(getClass().getResource("table_scene.fxml"));
        fxmlLoader.load();
        table_scene controller = fxmlLoader.getController();
        controller.C2.setCellValueFactory(new PropertyValueFactory<>("Classs"));
        controller.N2.setCellValueFactory(new PropertyValueFactory<>("Name"));
        controller.S2.setCellValueFactory(new PropertyValueFactory<>("Sec"));
        controller.table2.getColumns().addAll(controller.C2,controller.N2,controller.S2);
        controller.table2.setItems(getDetails());

  public ObservableList<TableItems> getDetails() {
     ObservableList<TableItems> list = FXCollections.observableArrayList();

       //Here are jdbc codes for retreiving the value of n1,c1,v1 and so on.
        //Tell me if i should add this code

        list.add(new TableItems(n1,c1,se1));
        list.add(new TableItems(n2,c2,se2));
        list.add(new TableItems(n3,c3,se3));
        list.add(new TableItems(n4,c4,se4));
       return list;
}

}

这是吸气剂和制定者的类别。

public class TableItems {
    private String Name;
    private int Classs;
    private String Sec;

   public TableItems(String Name, int Class, String Sec){
      this.Name=Name;
      this.Classs=Class;
      this.Sec=Sec;

}


public int getClasss() {
    return Classs;
}

public void setClasss(int classs) {
    Classs = classs;
}

public String getName() {
    return Name;
}
public void setName(String name) {
    Name = name;

}

public String getSec() {
    return Sec;
}

public void setSec(String sec) {
    Sec = sec;
}

}

这是我得到的错误..

EstablishedException in thread "JavaFX Application Thread" java.lang.IllegalStateException: Duplicate TableColumns detected in TableView columns list with titles 'Class', ' Name', 'Sec', 
at javafx.scene.control.TableView$5.onChanged(TableView.java:626)
at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)
at javafx.collections.ObservableListBase.addAll(ObservableListBase.java:245)
at sample.CaptainInfo.insertdata(CaptainInfo.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.MethodUtil.invoke(Unknown Source)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
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.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
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.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:432)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案