Reputation: 437
im studying programing at university, 2nd year now, and im getting started with java fxml scene builder. i know the basics and how to connect the code with the @FXML thing and so on. but im with a big problem. so, i basically create my window, some combo boxes etc, but the code java scene builder generetes comes with errores and i can't compile. I'll show you the code:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="582.0" prefWidth="804.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="lab001.InterFaceGraficaController">
<children>
<Label fx:id="label" layoutX="126.0" layoutY="120.0" minHeight="16.0" minWidth="69.0" />
<Label layoutX="64.0" layoutY="363.0" text="Label" />
<Label layoutX="64.0" layoutY="199.0" text="Label" />
<Label layoutX="64.0" layoutY="412.0" text="Label" />
<Label layoutX="47.0" layoutY="59.0" text="Label" />
<Button id="a" layoutX="115.0" layoutY="508.0" mnemonicParsing="false" onAction="#adicionar" text="add" />
<Button layoutX="229.0" layoutY="510.0" mnemonicParsing="false" onAction="#limpar" text="limpar" />
<ComboBox fx:id="combo" layoutX="111.0" layoutY="410.0">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="Item 1" />
<String fx:value="Item 2" />
<String fx:value="Item 3" />
</FXCollections>
</items>
</ComboBox>
<TextArea fx:id="txtA" layoutX="121.0" layoutY="114.0" prefWidth="200.0" wrapText="true" />
<Slider fx:id="sl" blockIncrement="1.0" layoutX="121.0" layoutY="365.0" majorTickUnit="2.0" max="10.0" min="1.0" minorTickCount="1" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="0.0" />
<ListView fx:id="filmes" layoutX="539.0" layoutY="152.0" prefHeight="200.0" prefWidth="200.0" />
<TextField fx:id="txt" layoutX="100.0" layoutY="56.0" prefWidth="200.0" />
</children>
</AnchorPane>
and i get errors like : JavaFX.scene.layout.anchorpane does not support property controller.
is this some jdk related error ? because this is pure auto-generated code, i haven't touched it.
Upvotes: 1
Views: 4656
Reputation: 1410
I had the same problem .
To solve this problem add this code to the first line of .FXML file :
<AnchorPane xmlns:fx="http://javafx.com/fxml" >
if this dosnt solve your problem , you should update your netbeans .
See this
Upvotes: 0
Reputation: 10979
In you the AnchorPane part of your code you have
xmlns:fx="http://javafx.com/fxml/1"
If you make a New Project -> JavaFX -> JavaFXML App, that line doesn't have the /1 on the end of the URL. As soon as you add something to the scene in Scene Builder, it changes back to having the /1 and it gives the error you mentioned.
I have the same problem as you except even though it has these errors, it still runs fine. I don't know if I should delete the /1 or not.
Using WinXPsp3 and Netbeans 7.4.1, JDK 7_40, Scene Builder 1.1
Upvotes: 0
Reputation: 848
I just copied your whole FXML and wrote the corresponding Controller in the corresponding package and got this result: http://puu.sh/4uZsk.png
How to replicate:
lab001
Main.java
with this contentpublic class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(this.getClass().getResource("application.fxml"));
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
InterFaceGraficaController
with this contentpublic class InterFaceGraficaController {
@FXML Label label;
@FXML ComboBox<String> combo;
public InterFaceGraficaController() {
System.out.println("init");
}
@FXML private void adicionar() {}
@FXML private void limpar() {}
}
and add your given FXML, if you still getting errors, you want to pastebin your errorlog and edit your post to show your progress.
Edit: Just to make sure; your controllers must have the functions you added in SceneBuilder, else it cannot bind them like adicionar
in your case.
Upvotes: 1
Reputation: 704
What version of SceneBuilder are you using? What version of Java are you trying to run under? That would be the first place to start in tracking this down.
Also, make sure that you controller has a no-args constructor. That would be the second place to check (although that usually results in a reflection error, I believe).
Upvotes: 0