Reputation: 57
I have designed a UI in javafx scene builder, which has a simple button in stackpane.And I have named the controller class as simplecclass. I have saved the fxml as simple.fxml. I have created a controller class in netbeans, which simply prints some msg on clicking the button.
In the NewFXBuilder java , I have loaded simple.fxml. Please find below the NewFXBuilder.java code.
package javafxapplication2;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXMLLoader;
public class NewFXbuilder extends Application {
@Override
public void start(Stage primaryStage) {
try {
StackPane page = (StackPane) FXMLLoader.load(NewFXbuilder.class.getResource("simple.fxml"));
Scene scene = new Scene(page);
primaryStage.setScene(scene);
primaryStage.setTitle("FXML is Simple");
primaryStage.show();
} catch (Exception ex) {
Logger.getLogger(NewFXbuilder.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
Application.launch(NewFXbuilder.class, (java.lang.String[])null);
}
}
My simple.fxml,simplecclass.java and NewFXbuilder.java all resides in the same folder javafxapplication2.
while running NewFXBuilder.java, but it gives me the following error.
javafxapplication2.NewFXbuilder start SEVERE: null javafx.fxml.LoadException: java.lang.ClassNotFoundException: simplecclass
Upvotes: 0
Views: 2259
Reputation: 57
The mistake I did was forgotten to add java packagename in the controller class name field in scene builder. It should have been packagename.simplecclass but I gave simplecclass alone,which is a mistake.
Upvotes: 1
Reputation: 38122
javafxapplication2.NewFXbuilder start SEVERE: null javafx.fxml.LoadException: java.lang.ClassNotFoundException: simplecclass
Looks like a problem in the FXML file. Make sure you import simplecclass in the FXML file.
Upvotes: 1