Partage
  • Partager sur Facebook
  • Partager sur Twitter

problème avec des d'imageView [javaFx]

problème avec des tableaux d'image view et un setImage

Sujet résolu
    26 mai 2022 à 9:32:54

    bonjour. 

    dans le cadre d'un projet moi et d'autre personne faisons un jeu de latice. Je m'occupe de la partie graphique du projet.

    afin de pouvoir simulé la pose de case, j'ai notamment créer des tableaux d'imageView.

    afin d'éviter d'avoir à me retrouver avec un énorme pavé de code, j'ai organisé mon projet de manière à ce que plusieurs classes fonctionnent entre elle.

    maintenant je vais vous montrer le code de la classe dans laquelle sont gérés les imagesView:

    package latice.utils;
    
    import javafx.scene.image.ImageView;
    
    public class GestionImageView {
    	private GestionImageSceneJeux gestion;
    	private ImageView ligneUn[];
    	private ImageView ligneDeux[];
    	private ImageView ligneTrois[];
    	private ImageView ligneQuatre[];
    	private ImageView ligneCinq[];
    	private ImageView ligneSix[];
    	private ImageView ligneSept[];
    	private ImageView ligneHuit[];	
    	private ImageView ligneNeuf[];	
    	
    	public GestionImageView() {
    		this.ligneUn = new ImageView[9];
    		this.ligneDeux = new ImageView[9];
    		this.ligneTrois = new ImageView[9];
    		this.ligneQuatre = new ImageView[9];
    		this.ligneCinq = new ImageView[9];
    		this.ligneSix = new ImageView[9];
    		this.ligneSept = new ImageView[9];
    		this.ligneHuit = new ImageView[9];
    		this.ligneNeuf = new ImageView[9];
    		for (int i = 0; i<9; i++) {
    			this.ligneUn[i] = new ImageView();
    			this.ligneDeux[i] =  new ImageView();
    			this.ligneTrois[i] = new ImageView();
    			this.ligneQuatre[i] = new ImageView();
    			this.ligneCinq[i] = new ImageView();
    			this.ligneSix[i] = new ImageView();
    			this.ligneSept[i] = new ImageView();
    			this.ligneHuit[i] = new ImageView();
    			this.ligneNeuf[i] = new ImageView();
    		}
    	
    
    		
    	}
    	
    	
    	
    	public void definirImage() {
    		for (int j=0; j<9; j++) {
    			ligneUn[j].setImage(gestion.cochonDindeRetourne());
    		}
    	}
    
    
    
    	public ImageView[] getLigneUn() {
    		return ligneUn;
    	}
    
    
    
    	public ImageView[] getLigneDeux() {
    		return ligneDeux;
    	}
    
    
    
    	public ImageView[] getLigneTrois() {
    		return ligneTrois;
    	}
    
    
    
    	public ImageView[] getLigneQuatre() {
    		return ligneQuatre;
    	}
    
    
    
    	public ImageView[] getLigneCinq() {
    		return ligneCinq;
    	}
    
    
    
    	public ImageView[] getLigneSix() {
    		return ligneSix;
    	}
    
    
    
    	public ImageView[] getLigneSept() {
    		return ligneSept;
    	}
    
    
    
    	public ImageView[] getLigneHuit() {
    		return ligneHuit;
    	}
    
    
    
    	public ImageView[] getLigneNeuf() {
    		return ligneNeuf;
    	}
    	
    	
    	
    }	
    

    ensuite j'utilise des images que je souhaite affecter au imageView, et pour cela j'utilise cette classe:

    package latice.utils;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    
    public class GestionImageSceneJeux {
    	//gestion des tuiles
    	private Image cochonDinde;
    	//gestion du plateau
    	private Image plateauImage;
    	
    
    	private ImageView plateau;
    
    	public GestionImageSceneJeux() {
    		
    
    		plateau = new ImageView();
    		
    		
    		try {
    			this.cochonDinde = new Image(new FileInputStream("src/main/resources/diamant.jpg"),90,90,false,false);
    		}catch(FileNotFoundException e) {
    			System.out.println("pas de cochon d'inde");
    		}
    
    		try {
    			this.plateauImage = new Image(new FileInputStream("src/main/resources/plateau/plateauLatice.png"),1000,1000,false,false);
    			plateau.setImage(plateauImage);
    		}catch(FileNotFoundException e) {
    			System.err.println("on ne trouve pas le plateau");
    		}
    		
    
    	}
    	
    
    	
    	public Image retournePlateau() {
    		return plateauImage;
    	}
    	public Image cochonDindeRetourne() {
    		return cochonDinde;
    	}
    	
    }
    

    (il y à d'autre classes, mais je pense que ces deux là en particulier sont la cause du problème).

    hors lorsque j'exécute ces deux classes se produits cette 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 latice.utils.GestionImageView.definirImage(GestionImageView.java:46)
    	at latice.scene.SceneJeux.initialisation(SceneJeux.java:59)
    	at latice.scene.GestionnaireDeScene.gestionScene(GestionnaireDeScene.java:26)
    	at latice.application.ApplicationMain.start(ApplicationMain.java:14)
    	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$4(WinApplication.java:185)
    	... 1 more
    Exception running application latice.application.ApplicationMain
    

    après une petite enquête, il s'avère que le responsable de tous ceci est une ligne en particulier.

    la voici:

    	public void definirImage() {
    		for (int j=0; j<9; j++) {
    			ligneUn[j].setImage(gestion.cochonDindeRetourne());
    		}
    	}

    j'ai beau creusé, je ne comprend pas comment faire pour régler ce problème.

    si vous pouvez m'aider alors je vous remercie d'avance  pour toutes réponse, et si vous estimez que vous avez besoin de plus d'information sur d'autre classe, alors dites le moi. Je n'hésiterais pas à modifier ceci pour vous permettre de m'aider.




    • Partager sur Facebook
    • Partager sur Twitter

    méfiez vous des cochon d'indes couineurs

    problème avec des d'imageView [javaFx]

    × 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