tryri Rien est vrai. Tout est permis | Bonjour, Je travail sur un projet Java de Space Invaders sur Intellij Idea, j'utilise donc javafx pour cela et pendant la compilation l'exception java.lang.reflect.InvocationTargetException apparait, plus loin dans les logs la première erreur est signaler au niveau d'une simple instanciation d'un label.
Si vous savez pourquoi cette erreur apparait et comment la corriger je vous remercierai
Voici le log complet:
Code :
- Exception in Application start method
- java.lang.reflect.InvocationTargetException
- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.base/java.lang.reflect.Method.invoke(Method.java:566)
- at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
- at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.base/java.lang.reflect.Method.invoke(Method.java:566)
- at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
- Caused by: java.lang.RuntimeException: Exception in Application start method
- at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
- at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
- at java.base/java.lang.Thread.run(Thread.java:834)
- Caused by: java.lang.IllegalAccessError: class javafx.scene.control.Control (in unnamed module @0x6b99a314) cannot access class com.sun.javafx.application.PlatformImpl (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.application to unnamed module @0x6b99a314
- at javafx.scene.control.Control.<clinit>(Control.java:87)
- at Accueil.menu(Accueil.java:51)
- at Accueil.<init>(Accueil.java:20)
- at Executable.restart(Executable.java:94)
- at Executable.start(Executable.java:69)
- at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
- at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
- at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
- at java.base/java.security.AccessController.doPrivileged(Native Method)
- at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
- at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
- at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
- at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
- ... 1 more
- Exception running application Executable
- Process finished with exit code 1
|
Comme vu dans le log voici la classe Executable et Acceuil
Executable:
Code :
- public class Executable extends Application {
- private Pane root;
- private Group caracteres;
- private GestionJeu gestionnaire;
- private int hauteurTexte;
- private int largeurCaractere;
- private Executable e = this;
- private boolean accesMenu = true;
- private Scene scene;
- public static void main(String[] args) {
- launch(args);
- }
- private void afficherCaracteres(){
- caracteres.getChildren().clear();
- int hauteur = (int) root.getHeight();
- for( ChainePositionnee c : gestionnaire.getChaines().chaines)
- {
- Text t = new Text (c.x*largeurCaractere,hauteur - c.y*hauteurTexte, c.c);
- t.setFont(Font.font ("Monospaced", 10));
- caracteres.getChildren().add(t);
- }
- }
- private void lancerAnimation() {
- Timeline timeline = new Timeline(
- new KeyFrame(Duration.seconds(0),
- new EventHandler<ActionEvent>() {
- @Override public void handle(ActionEvent actionEvent) {
- gestionnaire.jouerUnTour();
- afficherCaracteres();
- }
- }),
- new KeyFrame(Duration.seconds(0.025))
- );
- timeline.setCycleCount(Animation.INDEFINITE);
- timeline.play();
- }
- @Override
- public void start(Stage primaryStage) {
- primaryStage.setTitle("Space Invader" );
- Text t=new Text("█" );
- t.setFont(Font.font("Monospaced",10));
- hauteurTexte =(int) t.getLayoutBounds().getHeight();
- largeurCaractere = (int) t.getLayoutBounds().getWidth();
- restart();
- primaryStage.setScene(scene);
- primaryStage.setResizable(false);
- primaryStage.show();
- lancerAnimation();
- }
- public Pane getRoot() {
- return root;
- }
- public Group getCaracteres() {
- return caracteres;
- }
- public void setAccesMenu(boolean accesMenu) {
- this.accesMenu = accesMenu;
- }
- public GestionJeu getGestionnaire() {
- return gestionnaire;
- }
- public void restart(){
- if (accesMenu){
- root = new Accueil(this.e);
- }else{
- root= new AnchorPane(caracteres);
- }
- caracteres = new Group();
- gestionnaire = new GestionJeu(e);
- this.scene = new Scene(root,gestionnaire.getLargeur()*largeurCaractere,gestionnaire.getHauteur()*hauteurTexte);
- System.out.println(gestionnaire.getLargeur()*largeurCaractere +" "+gestionnaire.getHauteur()*hauteurTexte);
- if (!accesMenu){
- scene.addEventHandler(KeyEvent.KEY_PRESSED, (key) -> {
- if(key.getCode()== KeyCode.LEFT)
- gestionnaire.toucheGauche();
- if(key.getCode()==KeyCode.RIGHT)
- gestionnaire.toucheDroite();
- if(key.getCode()==KeyCode.SPACE)
- gestionnaire.toucheEspace();
- });
- }
- this.accesMenu = false;
- }
- }
|
Acceuil:
Code :
- public class Accueil extends Pane {
- private Executable e;
- public Accueil(Executable e){
- super();
- getChildren().addAll(banniere(), menu());
- this.e = e;
- }
- private HBox banniere(){
- HBox box = new HBox();
- box.setAlignment(Pos.CENTER);
- box.setSpacing(10);
- Image banniere = new Image("Images/banniere.png" );
- ImageView iBanniere = new ImageView();
- iBanniere.setImage(banniere);
- iBanniere.smoothProperty();
- box.getChildren().addAll(iBanniere);
- return box;
- }
- private FlowPane menu(){
- FlowPane box = new FlowPane();
- HBox box2 = new HBox();
- VBox box3 = new VBox();
- box.setOrientation(Orientation.VERTICAL);
- box.setAlignment(Pos.CENTER);
- box.setVgap(20);
- box2.setSpacing(20);
- Label tWave = new Label("Nombre de vagues" );
- TextField wave = new TextField();
- Button play = new Button("Jouer" );
- CheckBox activeBoss = new CheckBox("Boss" );
- ActionAccueil ac = new ActionAccueil(this.e);
- wave.setOnAction(ac);
- play.setOnAction(ac);
- activeBoss.setOnAction(ac);
- box3.getChildren().addAll(tWave, wave);
- box2.getChildren().addAll(play, box2);
- box.getChildren().addAll(box2, activeBoss);
- return box;
- }
- }
|
|