Java.lang.NullPointerException

Fermé
Koussette - 13 juin 2008 à 01:36
quentger Messages postés 81 Date d'inscription samedi 17 mars 2007 Statut Membre Dernière intervention 15 octobre 2010 - 13 juin 2008 à 09:22
Bonjour,jai un probleme de java.lang.NullPointerException dans mon programme java. Quand j'entre les informations dans mon interface graphique et je compille ,la console me donne deux erreurs java.lang.NullPointerException.
Merci d' avance, votre aide me sera d une grande utilité.
voici le code de mon programme


import java.awt.*;import java.awt.event.*;
import java.awt .*; import javax.swing .*; import javax.swing.border .*;
import javax.swing.event.*;
import javax.swing.*;
public class Projet extends JFrame implements ActionListener{
JLabel nom,prenom,adresse,code,ville,motpass,login,num;
JCheckBox n;
JPasswordField text;
Container c;
JPanel panHaut, panBas,pan;
JButton valider,retour,OK;
JTextField txtnom,txtpr,txta,txtc,txtv,txtlog,txtnum;
GridBagConstraints g;
String nomcli,precli,adressecli,mopasscli,villecli;
ControleurBan coba=new ControleurBan();
public Projet()
{
Dimension s=Toolkit.getDefaultToolkit().getScreenSize();
Dimension f=this.getSize();
if(f.width>s.width)
{
f.width=s.width;
}
if(f.height>s.height)
{
f.height=s.height;
}
this.setLocation((s.width-f.width)/3,(s.height-f.height)/3);
this.setResizable(true);
this.setTitle("Creation d un client");
this.setSize(1000, 500);
c=this.getContentPane();
panHaut = new JPanel();
panBas = new JPanel ();
pan=new JPanel();
panHaut.setLayout(new GridBagLayout());
panBas.setLayout(new GridBagLayout());
pan.setLayout(new GridBagLayout());
c.add (panHaut, BorderLayout.WEST);

c.add(pan, BorderLayout.EAST);
//c.add(panBas, BorderLayout.SOUTH);
c.setLayout(new GridBagLayout());
JLabel a=new JLabel("Entrez les renseignements concernants le client");
a.setFont(new Font("Helvetica",Font.BOLD+Font.ITALIC,13));
nom=new JLabel("Nom");
num=new JLabel("Numero de client");
txtnom=new JTextField();
prenom=new JLabel("Prenom");
txtpr=new JTextField();
adresse=new JLabel("Adresse");
txta=new JTextField();
code=new JLabel("Code Postal");
txtc=new JTextField();
ville=new JLabel("Ville");
txtv=new JTextField();
motpass=new JLabel("Mot de passe");
login=new JLabel("Login");
txtlog=new JTextField();
txtnum=new JTextField();
text=new JPasswordField();
n=new JCheckBox("Nouveau Banquier");
n.addActionListener(this);
valider=new JButton("Valider");
valider.addActionListener(this);
retour=new JButton("Retour");
retour.addActionListener(this);
/*ajout du label identite client */
g=new GridBagConstraints();
g.anchor=GridBagConstraints.CENTER ;g.insets=new Insets(100, 100, 30, 100);
g.gridx=0;g.gridy=0;
g.ipadx=20;panHaut.add(a,g);
/*ajout du label numero*/
g=new GridBagConstraints();
g.gridx=0;g.gridy=1;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=100;
g.insets=new Insets(10, 100, 30, 100);panHaut.add(num,g);
/*ajout du label nom*/
g=new GridBagConstraints();
g.gridx=0;g.gridy=2;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=100;
g.insets=new Insets(10, 100, 30, 100);panHaut.add(nom,g);
/*ajout du label prenom*/
g=new GridBagConstraints();
g.gridx=0;g.gridy=4;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=0;
g.insets=new Insets(10, 100, 30, 100);panHaut.add(prenom,g);
g=new GridBagConstraints();
g.gridx=0;g.gridy=6;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=0;
g.insets=new Insets(10, 100, 30, 100);panHaut.add(adresse,g);
/*ajout du label code*/
g=new GridBagConstraints();
g.gridx=0;g.gridy=8;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;//g.ipadx=3;
g.insets=new Insets(10, 100, 30, 100);panHaut.add(code,g);
/*ajout du label ville*/
g=new GridBagConstraints();
g.gridx=0;g.gridy=10;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;//g.ipadx=4;
g.insets=new Insets(10, 100, 30, 100);panHaut.add(ville,g);
/*ajout de la zone de texte numero*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=1;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=100;
panHaut.add(txtnum,g);
/*ajout de la zone de texte nom*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=2;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=100;
panHaut.add(txtnom,g);
/*ajout du label login*/
g=new GridBagConstraints();
g.gridx=0;g.gridy=2;g.anchor=GridBagConstraints.EAST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=100;
g.insets=new Insets(10, 0, 30, 10);
login.setVisible(false);pan.add(login,g);
/*ajout de la zone de texte login*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=2;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;g.ipadx=100;
txtlog.setVisible(false);
g.insets=new Insets(10, 50, 30, 20);
pan.add(txtlog,g);
/*ajout de la zone prenom*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=4;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;//g.gridx=1;
panHaut.add(txtpr,g);
/*ajout de zone adresse*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=6;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;//g.ipadx=2;
panHaut.add(txta,g);
//*ajout de la zone code*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=8;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;//g.ipadx=3;
panHaut.add(txtc,g);
/*ajout de la zone ville*/
g=new GridBagConstraints();
g.gridx=1;g.gridy=10;g.anchor=GridBagConstraints.WEST;
g.fill=GridBagConstraints.HORIZONTAL;//g.ipadx=4;
panHaut.add(txtv,g);
g = new GridBagConstraints();
g.gridx =0;g.gridy =0;
g.anchor =GridBagConstraints.WEST;
g.fill =GridBagConstraints.HORIZONTAL ;
g.ipadx =6;
g.insets = new Insets(0,20,2,0);
pan.add(n,g) ;
/*ajouter du label nouveau banquier*/
g = new GridBagConstraints();
g.gridx =0;g.gridy =4;
g.anchor =GridBagConstraints.WEST;
g.fill =GridBagConstraints.HORIZONTAL ;
g.ipadx =100;
g.insets =new Insets(0, 0, 0, 0);
motpass.setVisible ( false ) ;
pan.add(motpass,g) ;
/*ajouter d la zone mot de passe pour le nouveau
banquier*/
g = new GridBagConstraints();
g.gridx =1;g.gridy =4;
g.fill =GridBagConstraints.HORIZONTAL ;
g.ipadx =100;
g.insets =new Insets(10, 50, 30, 20) ;
text.setVisible ( false ) ;
pan.add(text,g) ;
/*ajout du bouton valider*/
g = new GridBagConstraints();
g.gridx =0;g.gridy =8;
g.ipadx =4;
g.insets =new Insets(0,0,40,0);
c.add(valider,g) ;

/*ajout du bouton retour*/
g = new GridBagConstraints();
g.gridx =1;g.gridy =8;
g.insets =new Insets(0,0,40,0);
c.add(retour,g) ;

pan.setBorder ( new TitledBorder("Banquier"));
panHaut.setBorder ( new TitledBorder("Client Simple"));
pack();
}
/*redefinition de la methode actionPerformed*/
public void actionPerformed (ActionEvent e)
{
if(e.getSource()==retour){
AccBanquier ab=new AccBanquier();
ab. setVisible(true);
setVisible(false);
}
if (n.isSelected())
{
n.setSelected(true);
login.setVisible(true);
txtlog.setVisible(true);
motpass.setVisible(true) ;
text.setVisible( true) ;
}

else
{
n.setSelected(false);
login.setVisible(false) ;
txtlog.setVisible( false) ;
motpass.setVisible(false) ;
text.setVisible( false) ;
}

// String numcli=txtnom.getText();
String nomcli=txtnom.getText();
String precli=txtpr.getText();
String adressecli=txta.getText();
String villecli=txtv.getText();
String mopasscli=text.getText();
boolean Banquier=false;
int cp = 0;
int numcli=0;
try{
cp=Integer.parseInt(txtc.getText());
}
catch(Exception ef){
JOptionPane.showMessageDialog(this,"Le code Postal que vous avez saisi est errone ou le champs est peut etre vide."
,"Message",JOptionPane.INFORMATION_MESSAGE,null);
}
if (cp != 0){

try{
if (n.isSelected()){
mopasscli=text.getText();
Banquier = true;
}
else{
mopasscli="";
Banquier = false;
}
coba.CreerClient(numcli,nomcli, precli, adressecli, cp, villecli, Banquier, mopasscli);
JOptionPane.showMessageDialog(this, "Le nouveau client a été ajouté avec succès!");
}
catch(Exception ex){
System.out.println(ex.toString());
}
}
}

private void windowClosing(WindowEvent e) {
System.exit(0);
}
//public static BaseDonnee database ;
public static void main(String[] args)
{
//database=new BaseDonnee("root","");
Projet p=new Projet();
p.setVisible(true);
}

}

2 réponses

Utilisateur anonyme
13 juin 2008 à 01:54
Bonjour,

Peux-tu nous indiquer le numero de ligne de ton programme qui provoque cette exception ?

Ce numero figure en debut de liste de l'exception en regard de la ligne .... Projet .... (le_numero).


Cordialement

Dan.
0
quentger Messages postés 81 Date d'inscription samedi 17 mars 2007 Statut Membre Dernière intervention 15 octobre 2010 9
13 juin 2008 à 09:22
pourrais-tu egalement indenter le code,c'est plus facile pour le relire
0

Discussions similaires