Partage
  • Partager sur Facebook
  • Partager sur Twitter

Bonjour j'ai une erreur java fx

Sujet résolu
    15 septembre 2019 à 17:26:32

    J'essaye de créer un launcher mais cela ne fonctionne pas

    erreur:

    Exception in Application start method
    java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Exception in Application start method
    	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$1(LauncherImpl.java:182)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NullPointerException
    	at fr.trxyy.launcherlib.utils.ResourceLocation.getMedia(ResourceLocation.java:25)
    	at fr.trxyy.launcherlib.interfaces.IScreen.drawAnimatedBackground(IScreen.java:93)
    	at fr.masterpala.launcher.LauncherPanel.createContent(LauncherPanel.java:40)
    	at fr.masterpala.launcher.LauncherMain.start(LauncherMain.java:34)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:863)
    	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
    	at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
    	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    	at com.sun.glass.ui.win.WinApplication.lambda$null$3(WinApplication.java:177)
    	... 1 more
    Exception running application fr.masterpala.launcher.LauncherMain

    et voici mon code :

    package fr.masterpala.launcher;
    
    import fr.trxyy.launcherlib.Init;
    import fr.trxyy.launcherlib.interfaces.LauncherBase;
    import fr.trxyy.launcherlib.interfaces.Mover;
    import fr.trxyy.launcherlib.utils.LauncherConfiguration;
    import fr.trxyy.launcherlib.utils.ResourceLocation;
    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.stage.Stage;
    import javafx.stage.StageStyle;
    
    public class LauncherMain extends Application {
    	
    	private ResourceLocation ressources;
    
    	@SuppressWarnings("static-access")
    	public static void main(String[] args) {
    		LauncherConfiguration config = new LauncherConfiguration();
    		config.setVersionId("1.7.10");
    		config.setAssetIndex("1.7.10");
    		config.setLaunchClass("net.minecraft.launchwrapper.Launch");
    		config.setDownloadUrl("https://scp15.cmws.fr/downloads/");
    		config.setCurrentlyMaintenance(false);
    		config.setMaintenanceUrl("");
    		config.setLaunchArguments("--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} --assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} --accessToken ${auth_access_token} --userProperties ${user_properties} --userType ${user_type} --tweakClass cpw.mods.fml.common.launcher.FMLTweaker");
    		Init.setConfiguration(config);
    		Init.registerLauncherConfiguration("Launcher Test", 850, 540, "launchertest", "/resources/");
    		Application.launch(args);
    	}
    
    	@Override
    	public void start(Stage primaryStage) throws Exception {
    		Scene primaryscene = new Scene(new LauncherPanel().createContent());
    		LauncherBase launcherBase = new LauncherBase(primaryStage, primaryscene, StageStyle.UNDECORATED, Mover.MOVE_ON_CLICK);
    		launcherBase.setIconImage(primaryStage, ResourceLocation.loadImage("favicon.png"));
    	}
    
    }
    
    package fr.masterpala.launcher;
    
    import fr.trxyy.launcherlib.Init;
    import fr.trxyy.launcherlib.LauncherConstants;
    import fr.trxyy.launcherlib.accounts.Account;
    import fr.trxyy.launcherlib.accounts.Authentication;
    import fr.trxyy.launcherlib.accounts.GameAuth;
    import fr.trxyy.launcherlib.components.LauncherAlert;
    import fr.trxyy.launcherlib.components.LauncherButton;
    import fr.trxyy.launcherlib.components.LauncherPasswordField;
    import fr.trxyy.launcherlib.components.LauncherTextField;
    import fr.trxyy.launcherlib.interfaces.IScreen;
    import fr.trxyy.launcherlib.interfaces.Mover;
    import fr.trxyy.launcherlib.interfaces.OptionsScreen;
    import fr.trxyy.launcherlib.utils.FontLoader;
    import javafx.application.Platform;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Parent;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.Pane;
    import javafx.stage.Stage;
    
    public class LauncherPanel extends IScreen{
    
    	private LauncherTextField usernameField;
    	private LauncherPasswordField passwordField;
    	private	LauncherButton loginButton;
    	private	LauncherButton minimizeButton;
    	private	LauncherButton settingsButton;
    	private	LauncherButton closeButton;
    	
    	
    	
    	
    @SuppressWarnings("static-access")
    	public Parent createContent() {
    		Pane contentPane = new Pane();
    		contentPane.setPrefSize(LauncherConstants.getWidth(), LauncherConstants.getHeight());
    		this.drawAnimatedBackground(contentPane, "background.mp4");
    		this.drawLogo(resources.loadImage("logo.png"), 150, 70, 600, 120, contentPane, Mover.MOVE_ON_CLICK);
    		
    		
    		
    		this.usernameField = new LauncherTextField(contentPane);
    		this.usernameField.setText(Init.getUserProps().getUsername());
    		this.usernameField.setStyle("-fx-background-color: rgba(53,89,119,0.4); -fx-text-fill: white;");
    		this.usernameField.setFont(FontLoader.loadFont("Roboto-Light.ttf","Roboto Lt", 18F));
    		this.usernameField.setPosition(LauncherConstants.getWidth() / 2 -100,LauncherConstants.getHeight() / 2 -400);		
    		this.usernameField.setPromptText("Pseudonyme/Email");
    		this.usernameField.setSize(200, 35);
    		
    		
    		
    		this.passwordField = new LauncherPasswordField(contentPane);
    		this.passwordField.setStyle("-fx-background-color: rgba(53,89,119,0.4); -fx-text-fill: white;");
    		this.passwordField.setFont(FontLoader.loadFont("Roboto-Light.ttf","Roboto Lt", 18F));
    		this.passwordField.setPosition(LauncherConstants.getWidth() / 2 -100,LauncherConstants.getHeight() / 2);		
    		this.passwordField.setPromptText("Pseudonyme/Email");
    		this.passwordField.setSize(200, 35);
    		
    		
    		
    		this.loginButton = new LauncherButton(contentPane);
    		this.loginButton.setText("Se Connecter");
    		this.loginButton.setStyle("-fx-background-color: rgba(53,89,119,0.4); -fx-text-fill: white;");
    		this.loginButton.setFont(FontLoader.loadFont("Roboto-Light.ttf","Roboto Lt", 18F));
    		this.loginButton.setPosition(LauncherConstants.getWidth() / 2 -50,LauncherConstants.getHeight() / 2 +40);		
    		this.loginButton.setSize(150, 35);
    		this.loginButton.setOnAction(new EventHandler<ActionEvent>() {
    			@Override
    			public void handle(ActionEvent k) {
    				trylogin(contentPane);
    			}
    			
    		});
    			
    		this.settingsButton = new LauncherButton(contentPane);
    			this.settingsButton.setSize(35, 35);
    			this.settingsButton.setPosition(LauncherConstants.getWidth() / 2 -100,LauncherConstants.getHeight() / 2 +40);		
    			this.settingsButton.setInvisible();
    			this.settingsButton.setStyle("-fx-padding: 0;");
    			ImageView settingsIcon = new ImageView(resources.loadImage("settings.png"));
    			settingsIcon.setFitWidth(this.settingsButton.getPrefWidth());
    			settingsIcon.setFitHeight(this.settingsButton.getPrefHeight());	
    			this.settingsButton.setGraphic(settingsIcon);
    			this.settingsButton.setOnAction(new EventHandler<ActionEvent>() {
    				@Override
    				public void handle(ActionEvent k) {
    					new OptionsScreen();
    				}
    				
    			});
    			
    			
    			
    			this.minimizeButton = new LauncherButton(contentPane);
    			this.minimizeButton.setSize(38, 22);
    			this.minimizeButton.setPosition(LauncherConstants.getWidth() -76,0);		
    			this.minimizeButton.setInvisible();
    			this.minimizeButton.setStyle("-fx-padding: 0;");
    			ImageView minimizeIcon = new ImageView(resources.loadImage("minimize.png"));
    			minimizeIcon.setFitWidth(this.minimizeButton.getPrefWidth());
    			minimizeIcon.setFitHeight(this.minimizeButton.getPrefHeight());	
    			this.minimizeButton.setGraphic(minimizeIcon);
    			this.minimizeButton.setOnAction(new EventHandler<ActionEvent>() {
    				@Override
    				public void handle(ActionEvent k) {
    					Stage stage = (Stage)((LauncherButton)k.getSource()).getScene().getWindow();
    					stage.setIconified(true);
    				}
    				
    			});
    			
    			this.closeButton = new LauncherButton(contentPane);
    			this.closeButton.setSize(38, 22);
    			this.closeButton.setPosition(LauncherConstants.getWidth() -38,0);		
    			this.closeButton.setInvisible();
    			this.closeButton.setStyle("-fx-padding: 0;");
    			ImageView closeIcon = new ImageView(resources.loadImage("close.png"));
    			closeIcon.setFitWidth(this.minimizeButton.getPrefWidth());
    			closeIcon.setFitHeight(this.minimizeButton.getPrefHeight());	
    			this.closeButton.setGraphic(closeIcon);
    			this.closeButton.setOnAction(new EventHandler<ActionEvent>() {
    				@Override
    				public void handle(ActionEvent k) {
    					Platform.exit();
    					System.exit(0);
    				}
    				
    			});
    			return contentPane;
    	}
    
    
    
    
    public void trylogin(Pane contentPane) {
    		if (usernameField.getText() == null) {
    			new LauncherAlert("Authentification echouchee !", "Tentative de connexion echouee car : Le pseudonyme doit comprendre au minimum 3 caracteres.");
    	}else if (usernameField.getText().length() > 2 && passwordField.getText().isEmpty()) {
    		GameAuth auth = new GameAuth(usernameField.getText(), passwordField.getText(), Authentication.OFFLINE);
    		if(auth.isLogged()) {
    			usernameField.setDisable(true);
    			passwordField.setDisable(true);
    			loginButton.setDisable(true);
    			Init.getUserProps().saveProps();
    			updateAndLaunch(contentPane);
    		}
    	} else if (usernameField.getText().length() > 2 && !passwordField.getText().isEmpty()) {
    		Account.setUsername(usernameField.getText());
    		Init.getUserProps().saveProps();
    		GameAuth auth = new GameAuth(usernameField.getText(), passwordField.getText(), Authentication.OFFICIAL);
    		if (auth.isLogged()) {
    			usernameField.setDisable(true);
    			passwordField.setDisable(true);
    			loginButton.setDisable(true);
    			Init.getUserProps().saveProps();
    			updateAndLaunch(contentPane);
    		} else {
    			new LauncherAlert("Authentification echouee !", 
    					"Impossible de se connecter l'authentification semble etre une authentification"
    					+ "'en-ligne'\n Il y a un probleme lors de la tentative de connexion.\n\n-Verifiez que le pseudonyme comprenne au minimum 3 caracteres."
    					+ "\n-Verifiez les majuscules et minuscules.\n-Assurez-vous d'utiliser un compte Mojang.");
    		}
    	}else {
    		new LauncherAlert("Authentification echouee !", "Impossible de se connecter"
    				+ "\n\nL'authentification semble etre une authentification 'hors-ligne"
    				+ "\nIl y a un probleme lors de la tentative de connexion: Le pseudonyme doit comprendre au minimum 3 caracteres.");
    	}
    		
    }}
    
    		
    





    -
    Edité par Master_Pala 15 septembre 2019 à 19:38:23

    • Partager sur Facebook
    • Partager sur Twitter

    Bonjour j'ai une erreur java fx

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown