0

When creating a new javafx project provided by maven, I get some errors in the console that cause the project to malfunction

I started writing the project and modifying a bit the one that is generated by default, but when calling some elements such as nodes and some events (in the case of one of the scene controllers), it generates errors to the console, the application opens, but does not it works as it should, I really don't know what to do, this project is the same as one that I had in eclipse ide, where it worked normally, but here when writing basically the same bop, the errors are generated, import the same project that I have in eclipse to vscode and in that case no error is generated and it works in the same way, I really don't know if it has to do with configuring the buildpath of the maven project in vscode, I don't know how to do it I'm new to vscode, I remember configuring the buildpath and some things in eclipse, but I have no idea how to do it here, if anyone has any suggestions or something I would appreciate it.

These are the errors that occur, and also the configuration of the project I think, it seems curious to me that the section for the javafx library does not appear

exception messages

And these are the main archive:

package com.scenes;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * JavaFX App
 */
public class App extends Application {

    private static Scene scene;

    @Override//creamos aqui 
    public void start(Stage stage) throws IOException {
        scene = new Scene(loadFXML("menu"));
        stage.setScene(scene);
        stage.show();
    }

    static void setRoot(String fxml) throws IOException {
        scene.setRoot(loadFXML(fxml));
    }

    private static Parent loadFXML(String fxml) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
        return fxmlLoader.load();
    }

    public static void main(String[] args) {
        launch();
    }

}

And the controller scene:

package com.scenes;


import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import javafx.animation.TranslateTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;//Deberemos importar un nodo para usarlo despues
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;


public class MenuCont implements Initializable{
    
    private Stage stage;
    private Scene scene;
    private Parent root;
    
    @FXML
    private Button Configuration;
    @FXML
    private StackPane StPane;
    @FXML
    private AnchorPane AnchorPane;
    
    public void SwitchToConfig(ActionEvent event) throws IOException {
        root = FXMLLoader.load(getClass().getResource("menu.fxml"));
        stage = (Stage)((Node)event.getSource()).getScene().getWindow();
        scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }
    
    public void switchToScene2(ActionEvent event) throws IOException {
        root = FXMLLoader.load(getClass().getResource("config.fxml"));
        stage = (Stage)((Node)event.getSource()).getScene().getWindow();
        scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }
    
    
    @FXML //ni puta idea de por que iba esta anotacion pero sin esto no lo reconoce xdd
    private void loadSecond(ActionEvent event) throws IOException {//funciona? si pero no ejecuta la animacion por alguna razon, asi que eso ver que es y tambien probar con el codigo de movimiento del nerdo del video que ando viendo xd
        //correcion, la mierda no carga nada del la otra escena.. wtf
        Parent root = FXMLLoader.load(getClass().getResource("config.fxml")); 
        Scene scene = Configuration.getScene();
        
        root.translateYProperty().set(scene.getHeight()); //aqui movemos el root (escena a cargar), en este caso la altura 
        StPane.getChildren().add(root);
        
        TranslateTransition translate = new TranslateTransition();
        translate.setNode(root);
        translate.setDuration(Duration.millis(150));
        translate.setToY(0);
        translate.setOnFinished(event1 -> {
            StPane.getChildren().remove(AnchorPane);//Esto se ejecuta al finalizar la animacion
        });
        
        TranslateTransition translat2 = new TranslateTransition();
        translat2.setNode(AnchorPane);
        translat2.setDuration(Duration.millis(200));
        translat2.setToY(-500);

        
        translate.playFromStart();
        translat2.playFromStart();
    }

    @Override
    public void initialize(URL arg0, ResourceBundle arg1) {
        // TODO Auto-generated method stub
        
    }
}

And finally, here is the maven project pom file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.scenes</groupId>
    <artifactId>periodic-table-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>13</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.scenes.App</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

jewelsea
  • 150,031
  • 14
  • 366
  • 406
Crynda
  • 3
  • 2
  • I don't know what you are doing or the cause of the issue you have. For the warnings missing `requires transitive`, you could read the [drinking explanation](https://stackoverflow.com/questions/46502453/whats-the-difference-between-requires-and-requires-transitive-statements-in-jav) though I am guessing the additional info won't help you solve your problem. – jewelsea Jul 17 '23 at 10:25
  • I am not sure what the issue is. but I would use the latest `maven-compiler-plugin` and `javafx-maven-plugin`. I am not sure if this will solve your issue. – SedJ601 Jul 17 '23 at 14:25
  • I am guessing that the requires transitive messages in your screenshot are compiler warnings, not actual errors. Probably, the compiler is warning that a type in a required module in your project won't be available automatically to users of your project. If your project is to build a stand-alone application and not a library to be used by others, the requires transitive warnings probably do not matter. As an aside, it is better to include the compiler output as text formatted as code rather than as a screenshot. – jewelsea Jul 17 '23 at 17:39
  • As noted by @jewelsea, that is a warning, not an error. Though I'm not sure if it's an IDE inspection or a compiler warning (specifically ECJ, not javac). Anyway, that warning is saying you have a type exposed by a public member of an "exported" package, but the type comes from an external module. For example, you have `Stage` as a parameter of the required `start` method. That class comes from `javafx.graphics`. And since you must `exports` the application's package to at least that module, you are "exporting" an API where consumers would transitively require the `javafx.graphics` module. – Slaw Jul 17 '23 at 18:13
  • The "fix" is to have `requires transitive javafx.graphics` instead of just `requires javafx.graphics` (or in addition to e.g., `requires javafx.controls` if that's all you have; the controls module transitively requires the graphics module, hence why you don't need to explicitly require both to use types from both in _your own module_). Though the more appropriate fix is to have a qualified exports: `exports to javafx.graphics`. But I don't know if that will get rid of the warning (it doesn't, or at least hasn't, in VS Code), even though it makes the warning is meaningless. – Slaw Jul 17 '23 at 18:16
  • In your question, you note that the app *"does not works as it should"* -> That is not specific enough for somebody to help. The nature of the failure is not relayed, no stack trace or exception is provided, nor is there a description of the expected behavior and how the actual behavior differs. You can edit the question to improve it. – jewelsea Jul 17 '23 at 19:07
  • Small update, I reviewed the code a bit and now it works, so that's how they comment, they seem to be just warnings, but I'm a little worried if it has any repercussions on users who use the program in the future – Crynda Jul 18 '23 at 03:58

0 Answers0