IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage Java Discussion :

difficulte avec mon List <Shape>


Sujet :

Langage Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de poulette3000
    Profil pro
    Inscrit en
    Août 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Août 2006
    Messages : 183
    Par défaut difficulte avec mon List <Shape>
    Voilà mon but est de récuperer des lignes, et franchement je debute en Java , et je crois que je pourrai pas résoudre ça sans votre aide

    J'ai un classe qui dérive de JPanel dans laquelle on trace des courbe GraphePh, j'y ai inseré un attribut private
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    public Class GraphePh{ ....
    private List <Shape> shapes ;
    ...}
    Plus loin dans le constructeur j'ai défini mes shapes comme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    shapes = new ArrayList<Shape>(); // collection de forme utilisable à la pause
    Ensuite les courbes se dessinent au fil du temps alors je remplis en meme temps ma collection de forme dans une methode AfficherPoint (en fait c des lignes)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    public Afficher Point(){ .....
    if(ok){
    g.drawLine(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][0], abcisseEnCours+x, tab_coor[indiceTab][i][0]);
    shapes.add(new Line2D.Double(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][0], abcisseEnCours+x, tab_coor[indiceTab][i][0]));
    }
    ....
    if(ok){
    {g.drawLine(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][c], abcisseEnCours+x, tab_coor[indiceTab][i][c]);
    shapes.add(new Line2D.Double(abcisseEnCours-1+x, tab_coor[indiceTab-(int)pas][i][c], abcisseEnCours+x, tab_coor[indiceTab][i][c]));
    }
    }
    et J'ai aussi fait un accesseur pour la List, je sais pas si c correc, parce que je m'y connais pas trop
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     public List <Shape> getmesShapes() { // On ajoutera les shapes au JPanel
            return shapes;
        }
    Ensuite j'ai crée une JPanel, qui affichera cette fameuse collec de Shape, comme ça j'affiche à part sur une autre fenetre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
     
    public class affichShapes extends JPanel{
    	private AppletPh2 app;
    	private List <Shape> shapes ;
     
    	public affichShapes (){
    		super();
    		this.setSize(600,600);
    		//List <Shape> shapes =  new ArrayList<Shape>();
     
    	}
     
        protected void paintComponent(Graphics g) {
        // TODO Raccord de méthode auto-généré
        	super.paintComponent(g);
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        //Pour chaque forme de la collection
        shapes =  app.getFenetreGraphe().getGraphePh().getmesShapes();
        for(Shape shape  :  shapes) {
            //On dessine la forme
            g2d.draw(shape);
        		}
        }
     
    }
    mais les messages arrivent au moment où la fen contenant le panel surgit !
    Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
    at AppletPh2.fenetreGraphe.affichShapes.paintComponent(affichShapes.java:35)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)


    c'est ça qui me dit qui va pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    shapes =  app.getFenetreGraphe().getGraphePh().getmesShapes();
    MERCI

  2. #2
    Membre émérite
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Par défaut
    est null au choix :

    app
    app.getFenetreGraphe()
    app.getFenetreGraphe().getGraphePh()

    suffit d'ajouter des System.out afin de déterminer lequel

  3. #3
    Membre confirmé Avatar de poulette3000
    Profil pro
    Inscrit en
    Août 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Août 2006
    Messages : 183
    Par défaut
    tu veux dire System.out.println( app) par exemple ?

  4. #4
    Membre émérite
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Par défaut
    Oui
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    //Pour chaque forme de la collection
    System.out.println( app);
    System.out.println( app.getFenetreGraphe());
    System.out.println( app.getFenetreGraphe().getGraphePh());
    shapes =  app.getFenetreGraphe().getGraphePh().getmesShapes();
    ca ne corrige pas le bug , mais cela permettra de savoir quel élément est null.

  5. #5
    Membre confirmé Avatar de poulette3000
    Profil pro
    Inscrit en
    Août 2006
    Messages
    183
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Août 2006
    Messages : 183
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    shapes =  app.getFenetreGraphe().getGraphePh().getmesShapes();
        System.out.println(app);
        System.out.println(app.getFenetreGraphe());
    System.out.println(app.getFenetreGraphe().getGraphePh().getmesShapes());

    il m'a pas dit grd chose, je vois rien dans le message d'erreur

    Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
    at AppletPh2.fenetreGraphe.affichShapes.paintComponent(affichShapes.java:35)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
    at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    at java.awt.Container.paint(Unknown Source)
    at sun.awt.RepaintArea.paintComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  6. #6
    Membre émérite
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Par défaut
    les traces doivent être placées avant l'erreur

  7. #7
    Expert confirmé
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 45
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Par défaut
    Décommentes cette ligne dans ton constructeur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    //List <Shape> shapes =  new ArrayList<Shape>();
    En effet ta liste n'est initialisée à aucun moment, d'où la nullPointerException que tu obtiens

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Une difficulté avec mon slide
    Par felixpat dans le forum PHP & Base de données
    Réponses: 6
    Dernier message: 24/03/2014, 15h35
  2. Difficultés avec les Listes chaînées de classe
    Par Tyra3l dans le forum Langage
    Réponses: 4
    Dernier message: 13/01/2011, 18h07
  3. difficulté avec les listes chainées
    Par sneb5757 dans le forum Débuter
    Réponses: 3
    Dernier message: 30/09/2008, 09h34
  4. Difficulté avec Zone de Liste modifiable
    Par YOP33 dans le forum IHM
    Réponses: 2
    Dernier message: 17/01/2008, 19h24
  5. Réponses: 7
    Dernier message: 24/01/2006, 11h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo