This discussion is archived
2 Replies Latest reply: Dec 5, 2012 7:57 AM by 902665 RSS

Error with using a CustomControl

902665 Newbie
Currently Being Moderated
Hi Javafx- friends, i have a Problem with my code. I hope, you can help.

I want to use a CustomControl of the control ComboBox. Here my code:
public class CustomComboBox extends ComboBox{
//    @FXML
//    ComboBox this;
    
    Boolean _errorMode;

    public CustomComboBox(Boolean _errorMode) {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CustomComboBox.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
        this._errorMode = _errorMode;
    }

    public CustomComboBox(Boolean _errorMode, ObservableList ol) {
        super(ol);
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CustomComboBox.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
        
        this._errorMode = _errorMode;
       
    }
    

    public Boolean selectItem(Object object){
        int i = 0;
        while(i < this.getItems().size()){
            if(this.getItems().get(i).equals(object)){
                 this.setValue(object);
                 return true;
            }else{
                i++;
            }
        }
        clearSelection();
        return false;
    }
 
FXML
<fx:root type="javafx.scene.control.ComboBox" xmlns:fx="http://javafx.com/fxml">
</fx:root>

 
and my CustomListCell, which use the CustomComboBox

FXML
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import custom.*?>


<VBox prefHeight="200.0" prefWidth="400.0" xmlns:fx="http://javafx.com/fxml" fx:controller="listcell.ListCellInfoTaskController">
  <children>
    <FlowPane prefHeight="-1.0" prefWidth="-1.0">
      <children>
        <Label fx:id="lDate" text="Datum:" />
        <Label fx:id="lDateValue" text="" />
        <Label fx:id="lStatus" text="Status:" />
        <CustomComboBox fx:id="cbStatus" />
      </children>
    </FlowPane>
    <FlowPane prefHeight="-1.0" prefWidth="-1.0" prefWrapLength="100.0">
      <children>
        <Label fx:id="lAuthor" text="Autor:" />
        <Label fx:id="lAuthorValue" text="" />
      </children>
    </FlowPane>
    <TextArea fx:id="taActualGeneralMessage" editable="false" prefWidth="200.0" wrapText="true" />
  </children>
</VBox>

 
If the fxml will build, the following error will be thrown:

Dez 05, 2012 2:02:52 PM listcell.ListCellInfoTask <init>
SEVERE: null
javafx.fxml.LoadException: java.lang.InstantiationException: custom.CustomComboBox
     at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:813)
     at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:567)
     at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
     at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
     at listcell.ListCellInfoTask.<init>(ListCellInfoTask.java:36)
     at guiInfo.InfoTaskController$2.call(InfoTaskController.java:166)
     at guiInfo.InfoTaskController$2.call(InfoTaskController.java:163)
     at com.sun.javafx.scene.control.skin.ListViewSkin.createCell(ListViewSkin.java:189)
     at com.sun.javafx.scene.control.skin.ListViewSkin$1.call(ListViewSkin.java:63)
     at com.sun.javafx.scene.control.skin.ListViewSkin$1.call(ListViewSkin.java:61)
     at com.sun.javafx.scene.control.skin.VirtualFlow.getCell(VirtualFlow.java:1497)
     at com.sun.javafx.scene.control.skin.VirtualFlow.getCellLength(VirtualFlow.java:1523)
     at com.sun.javafx.scene.control.skin.VirtualFlow$3.call(VirtualFlow.java:478)
     at com.sun.javafx.scene.control.skin.VirtualFlow$3.call(VirtualFlow.java:476)
     at com.sun.javafx.scene.control.skin.PositionMapper.computeViewportOffset(PositionMapper.java:143)
     at com.sun.javafx.scene.control.skin.VirtualFlow.layoutChildren(VirtualFlow.java:1001)
     at javafx.scene.Parent.layout(Parent.java:1018)
     at javafx.scene.Parent.layout(Parent.java:1028)
     at javafx.scene.Parent.layout(Parent.java:1028)
     at javafx.scene.Parent.layout(Parent.java:1028)
     at javafx.scene.Parent.layout(Parent.java:1028)
     at javafx.scene.Parent.layout(Parent.java:1028)
     at javafx.scene.Scene.layoutDirtyRoots(Scene.java:513)
     at javafx.scene.Scene.doLayoutPass(Scene.java:484)
     at javafx.scene.Scene.access$3900(Scene.java:169)
     at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2199)
     at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
     at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:460)
     at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:329)
     at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
     at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
     at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:67)
     at java.lang.Thread.run(Thread.java:722)

Where is my mistake?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points