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

Agents de placement/Fenêtres Java Discussion :

Erreur at java.awt.Container.addImpl(Unknown Source)


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Nouveau membre du Club
    Femme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2009
    Messages
    29
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : Maroc

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 29
    Points : 36
    Points
    36
    Par défaut Erreur at java.awt.Container.addImpl(Unknown Source)
    Bonsoir

    je suis entrain de programmer une application d'annuaire téléphonique le problème c que Eclipse m'affiche toujours le même erreur .

    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl(Unknown Source)
    voici Mon Code :
    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
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
     
    import javax.swing.*;
    import java.awt.*;
    import java.sql.*;
    import java.awt.event.*;
     
     
    public class App extends JFrame{
     
     
        private JPanel ButtonPanel;
        private JPanel TitrePanel;
        private JPanel ResultPanel;
        private JPanel RechPanel;
        private JPanel BodyPanel;
     
     
        private JLabel RechTitre = new JLabel("Recherche");
        private JLabel ResultLabel= new JLabel("Resultat");
        private JLabel RechLabel= new JLabel("Vous Cherchez :");
        private JLabel GSMLabel= new JLabel("GSM");
        private JLabel LigneLabel= new JLabel("Ligne");
        private JLabel NomLabel= new JLabel("Nom");
        private JLabel PosteLabel= new JLabel("Poste");
        private JLabel PrenomLabel= new JLabel("Prenom");
        private JLabel ServiceLabel= new JLabel("Service");
        private JLabel TitleLabel= new JLabel("Centre Hospitalier Universitaire Ibn Rochd");
     
     
        private JComboBox ChoixBox;
     
        private JButton NextButton;
        private JButton ValiderRech;
        private JButton BeforeButton;
     
     
        private JTextField GSMField;
        private JTextField LigneField;
        private JTextField PosteField;
        private JTextField PrenomField;
        private JTextField NomField;
        private JTextField RechField;
        private JTextField ServiceField;
     
        private JSeparator jSeparator1;
     
     
        public  App(){
     
            this.setTitle("Centre Hospitalier Universitaire Ibn Rochd");
            this.setSize(500, 300);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            this.setLocationRelativeTo(null);
     
     
            this.setLayout(new BorderLayout());
            this.getContentPane().add(TitrePanel,BorderLayout.NORTH);
            this.getContentPane().add(BodyPanel, BorderLayout.CENTER);
          //  BodyPanel.add(RechPanel,BorderLayout.NORTH);
          //  BodyPanel.add(ResultPanel,BorderLayout.SOUTH);
            this.getContentPane().add(ButtonPanel,BorderLayout.SOUTH);
            this.setVisible(true);        
     
           ValiderRech.setText("Valider");
           NextButton.setText("Suivant");
           BeforeButton.setText("Précédent");
     
           ChoixBox.setModel(new DefaultComboBoxModel(new String[] { "Nom", "Service", "Poste", "GSM" }));
     
           add(TitrePanel,BorderLayout.NORTH);
           add(BodyPanel, BorderLayout.CENTER);
           BodyPanel.add(RechPanel,BorderLayout.NORTH);
           BodyPanel.add(ResultPanel,BorderLayout.SOUTH);
           add(ButtonPanel,BorderLayout.SOUTH);
     
            TitrePanel.add(TitleLabel);
            TitrePanel.setBackground(new Color(255, 255, 255));
            TitleLabel.setHorizontalAlignment(SwingConstants.CENTER);
     
     
            RechPanel.add(RechTitre);
            RechPanel.add(RechLabel);
            RechPanel.add(RechField);
            RechPanel.add(ChoixBox);
            RechPanel.add(ValiderRech);
            RechPanel.add(jSeparator1);
            RechTitre.setHorizontalAlignment(SwingConstants.CENTER);
     
            ResultPanel.add(ResultLabel);
            ResultPanel.add(NomLabel);
            ResultPanel.add(NomField);
            ResultPanel.add(PrenomLabel);
            ResultPanel.add(PrenomField);
            ResultPanel.add(ServiceLabel);
            ResultPanel.add(ServiceField);
            ResultPanel.add(PosteLabel);
            ResultPanel.add(PosteField);
            ResultPanel.add(LigneLabel);
            ResultPanel.add(LigneField);
            ResultPanel.add(GSMLabel);
            ResultPanel.add(GSMField);
            ResultLabel.setHorizontalAlignment(SwingConstants.CENTER);
     
            ButtonPanel.add(NextButton);
            ButtonPanel.add(BeforeButton);
     
            ChoixBox.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    ChoixBoxActionPerformed(evt);
                }
            });
            ValiderRech.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    ChoixBoxActionPerformed(evt);
                }
            });
            NextButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    ChoixBoxActionPerformed(evt);
                }
            });
            BeforeButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    ChoixBoxActionPerformed(evt);
                }
            });
        }
            private void ChoixBoxActionPerformed(ActionEvent evt) {                                         
             }
     
            private void ValiderRechActionPerformed (ActionEvent evt)
            {
            	String choix = String.valueOf(ChoixBox.getSelectedItem());
                String Rech = RechField.getText();
                String query;
                if (choix.equals("Nom"))
                {
                    query = " Select * from Personnel where Nom = upper("+Rech+")/";
                    // requete
                }
                else  if (choix.equals("Service"))
                       {
                          // requete
                    query = " Select * from Personnel where idService = ( select Idser from Services where  NomSer = upper("+Rech+")/";
                        }
                      else if (choix.equals("Poste"))
                           {
                             //requete
                          query = " Select * from Personnel where poste = "+Rech+"/";
                              }
                            else if (choix.equals("Ligne"))
                             {
                                //requete
                                query = " Select * from Personnel where Ligne = "+Rech+"/";
                              }
                            else
                            {
                                   // requete
     
                                   query = " Select * from Personnel where GSM = "+Rech+"/";
                            }
     
     
     
            }
            private void NextButtonActionPerformed(ActionEvent evt)
            {
     
            }
     
            private void BeforeButtonActionPerformed(ActionEvent evt)
            {
     
            }
     
     
     
     
     
    	public static void main(String[] args) {
     
    		App Fenetre = new App();
     
    	}
     
    }
    désolé si jamais j'ai fait des erreurs banales ! je suis débutante !
    Merci pour votre aide

  2. #2
    Expert confirmé
    Avatar de slim_java
    Homme Profil pro
    Enseignant
    Inscrit en
    Septembre 2008
    Messages
    2 272
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 39
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Septembre 2008
    Messages : 2 272
    Points : 4 539
    Points
    4 539
    Par défaut
    Salut,


    Si on voit le code que tu as fourni, on remarque bien que tu as pas fais la création des instances pour les attributs de ta classe App ; donc pas d'objet créé et seulement des références.

    Comment faire alors l'instanciation ?

    Un objet est une instance de classe, la création d'objets s'appelle donc l'instanciation. Cette instanciation se fait grâce à l'opérateur new suivi du nom de la classe à instancier et de parenthèses contenant les paramètres d'instanciation.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
     
        private JPanel ButtonPanel = new JPanel();
        private JPanel TitrePanel= new JPanel();
     
       // faites ce traitement pour le reste de la liste des attributs

  3. #3
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,

    Citation Envoyé par saloua2200 Voir le message
    Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.addImpl(Unknown Source)
    Quel est le stacktrace complet de l'exception ??? Car sans la suite il est complètement inutile...


    Remontes toutes les lignes du stacktrace jusqu'à arriver dans ton code, et là magie tu auras la ligne posant problème !

    a++

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

Discussions similaires

  1. Erreur java.lang.String.charAt(Unknown Source)
    Par AbA2L dans le forum Débuter avec Java
    Réponses: 5
    Dernier message: 13/06/2015, 18h31
  2. erreur java (unknown source)
    Par jpclutier dans le forum Général Java
    Réponses: 5
    Dernier message: 15/12/2010, 14h02
  3. Réponses: 3
    Dernier message: 19/03/2009, 15h53
  4. Réponses: 2
    Dernier message: 30/04/2008, 11h30
  5. pb "java.util.Arrays.mergeSort(Unknown Source)"
    Par kamalkam dans le forum API standards et tierces
    Réponses: 12
    Dernier message: 08/05/2006, 12h38

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