Getting Errors parsing FXML file into a javafx program - java

Im Getting These Errors when trying to parse this FXML file into my Java Program.The code for when i load in the FXML file and where i get the errors are bellow
package mediarealm;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class MediaRealm extends Application {
#Override
public void start(Stage primaryStage) {
Parent root = null;
primaryStage.initStyle(StageStyle.UNDECORATED);
try {
root = FXMLLoader.load(getClass().getResource("/rsrc /UIManagmentDefaultState.fxml"));
} catch (IOException ex) {
Logger.getLogger(MediaRealm.class.getName()).log(Level.SEVERE, null, ex);
}
root.setStyle("-fx-background-color: #000000;");
Scene scene = new Scene(root, 1280, 720);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
It could possibly because of the code Bellow but I don't think it is i'm trying to load in some of the elements from the fxml file into the rest of my code so that i can have full access to said elements with java.
package mediarealm;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
public class Controller
{
#FXML private Button ExitButton;
#FXML private static Button myVideos;
public static void doshit()
{
myVideos.setText("Addison is gay!");
}

Probably a long shot, but the line
< fx:id="myMusic" /Button>
is no correct XML, it rather should be
</Button>

Related

Getting syntax error while binding label to StringProperty

I am just starting to learn javafx.I am trying to make a simple application where you enter into a textfield and simultaniously give it out via the label.
Heres the main class
package testing;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class testing extends Application {
private Stage primaryStage;
private BorderPane RootLayout;
#Override
public void start(Stage primaryStage) {
this.primaryStage=primaryStage;
this.primaryStage.setTitle("First Application");
initRootLayout();
initProjectTest();
}
public static void main(String[] args) {
launch(args);
}
public Stage getPrimaryStage() {
return primaryStage;
}
public void initRootLayout() {
try{ FXMLLoader loader=new FXMLLoader();
loader.setLocation(testing.class.getResource("view/RootLayout.fxml"));
RootLayout=(BorderPane)loader.load();
primaryStage.setScene(new Scene(RootLayout));
primaryStage.show();
}
catch(IOException e) {
e.printStackTrace();
}
}
public void initProjectTest() {
try {
FXMLLoader loader=new FXMLLoader();
loader.setLocation(testing.class.getResource("view/ProjectTest.fxml"));
AnchorPane ProjectTest=(AnchorPane)loader.load();
RootLayout.setCenter(ProjectTest);
}
catch(IOException e) {
e.printStackTrace();
}
}
}
Here is the controller class
package testing.view;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class ProjectTestController {
#FXML
private Label label1=new Label();
#FXML
private TextField textfield1=new TextField();
label1.textProperty().bind(textfield1.textProperty());
}
If I try to implement it via a button where the text is updated everytime I click the button(via a onAction function) the code works fine. However I get syntax error when I try to bind. I tried to search for answers but none of were having syntax errors.

Beginner; GUI not appearing?

I'm new to java and coding. I tried searching this problem but could not find a solution.
I was given this code as an example on paper. I tried to recreate it in Eclipse but when I run the code, nothing happens (no gui popup or anything like that). It wouldn't work in jGrasp either. Anyone know what is wrong?
Thanks
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
import javafx.scene.media.AudioClip;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
public class AudioShuffle extends Application {
private AudioClip audio1;
private AudioClip audio2;
private AudioClip audio3;
private AudioClip audio4;
private Button play, stop, shuffle;
#Override
public void start(Stage primaryStage) {
String clipURL = "http://www.music.helsinki.fi/tmt/opetus/uusmedia/esim/a2002011001-e02-16kHz.wav";
audio1 = new AudioClip(clipURL);
play=new Button("PLAY");
play.setStyle("-fx-font:20 Arial");
stop=new Button("STOP");
stop.setStyle("-fx-font:20 Arial");
play.setOnAction(this::processButtonPress);
stop.setOnAction(this::processButtonPress);
FlowPane pane = new FlowPane(play, stop);
pane.setAlignment(Pos.CENTER);
pane.setHgap(20);
pane.setStyle("=fx=background=color: cyan");
Scene scene = new Scene(pane, 300,100);
primaryStage.setTitle("Audio Playlist");
primaryStage.setScene(scene);
primaryStage.show();
}
public void processButtonPress(ActionEvent event){
if(event.getSource()==play){
audio1.play();
}
else if(event.getSource()==stop){
audio1.stop();
}
}
public static void main(String[] args){
}
}

JavaFX 8 on Button Click show other Scene

Hello I am currently working on a PIN Generator for my work and as I am completely new to Java I am having a few difficulties, especially when using JavaFX.
I want to make the programm show another .fxml file when clicking on one of each buttons.
Here is my code:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class main extends Application {
public static void main(String[] args) {
Application.launch(main.class, args);
}
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/view/main.fxml"));
stage.setTitle("PIN-Generator");
stage.setScene(new Scene(root, 600, 400));
stage.show();
}
}
I have created a controller Class for each button on the scene.
Controller Class Code:
package view;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class MainController {
#FXML
private Label dpmadirektpropingenerator;
#FXML
private Button unlockPinButton;
#FXML
private Button confirmationPinButton;
}
This code should works.
Modify your main class like this:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class main extends Application {
public static void main(String[] args) {
Application.launch(main.class, args);
}
static Stage stg;
#Override
public void start(Stage stage) throws Exception {
this.stg = stage;
Parent root = FXMLLoader.load(getClass().getResource("/view/main.fxml"));
stage.setTitle("PIN-Generator");
stage.setScene(new Scene(root, 600, 400));
stage.show();
}
}
and here is your pressButton function:
public void pressButton(ActionEvent event){
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("sedondFXML.fxml"));
Parent root = (Parent) fxmlLoader.load();
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
main.stg.close();
} catch(Exception e) {
e.printStackTrace();
}
}

How can I import a layout from another package in JavaFX?

Here is the code:
package application;
//imports
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import application.view.*; //i've tried import the package, but i don't know if this is correct
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
//here is my issue:
**Pane root = FXMLLoader.load(getClass().getResource("application.view.Lay.fxml"));**
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
}
I've Tried this, but it doesn't work, what am I doing wrong?
Thanks for your time!
Try
Pane root = FXMLLoader.load(getClass().getResource("/application/view/Lay.fxml"));
If we have a lengthy package name, we have to replace every dot "." with forward slash.
Like if package name that contain views/fxml files is
package org.itsoftsolutions.view;
Than we have to provide path like this
FXMLLoader.load(getClass().getResource("/org/itsoftsolutions/view/login.fxml"));

FXMLLoader.load can't be resolved to a type

So I created a FXML interface using JavaFX's Scene Builder tool, and I'm trying to load it via my code. However, I ran into this error when trying to load my FXML document: FXMLLoader.load can't be resolved to a type.
Here is my code:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Driver extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
Parent root = new FXMLLoader.load(getClass().getResource("interface.fxml"));
Scene scene = new Scene(root, 600, 400);
primaryStage.setTitle("Wiki Scraper");
primaryStage.setScene(scene);
primaryStage.show();
}
}
My FXML document is contained in the most top level project folder.
What am I doing incorrectly?
Try to split it up this way:
FXMLLoader loader = new FXMLLoader(this.getClass().getResource("DefaultFrame.fxml"));
Parent root = (Parent) loader.load();
dfController = loader.getController();

Categories

Resources