zeddman
-
Modifié par cs_Julien39 le 22/03/2014 à 12:23
KX
Messages postés16701Date d'inscriptionsamedi 31 mai 2008StatutModérateurDernière intervention26 mai 2023
-
21 mars 2014 à 18:39
Bonjour,
j'ai un splash ! d'un cout il marche mais pendant qu'il marche, il y a des erreur comme cela
Exception in thread "Thread-2" java.lang.NullPointerException
at splash1$MonRunnable.run(splash1.java:44)
at java.lang.Thread.run(Thread.java:619)
voici mon code
public class splash1 extends javax.swing.JWindow {
Thread monThread;
public void fermer(){
this.dispose();
}
public class MonRunnable implements Runnable {
public void run() {
for (int j = 1; j <= 100; j++) // on fait une boucle pour que la JProgressBar "avance"
{
progress.setValue(j);
try {
monThread.sleep(20);
} catch (Exception e) {
// e.printStackTrace();
}
}
fermer();
pageG welcome = new pageG();
welcome.setLocationRelativeTo(welcome.getParent());
welcome.setVisible(true);
}
}
public splash1() {
Thread monthread = new Thread(new MonRunnable());
monthread.start();
initComponents();
}
public static void main(String args[]) {
try {
UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Entre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Entre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Entre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Entre.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (Exception e)
{
e.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
splash1 Fenetre = new splash1();
Fenetre.setLocationRelativeTo(Fenetre.getParent());
Fenetre.setVisible(true);
}
});
}
KX
Messages postés16701Date d'inscriptionsamedi 31 mai 2008StatutModérateurDernière intervention26 mai 2023126 21 mars 2014 à 18:39
Le problème c'est ton objet progress.
Il est initialisé dans initComponents, après avoir monthread.start() dans le constructeur. Or ton thread utilises progress pour faire son setValue, mais à ce moment là, progress n'a pas encore sa valeur, donc NullPointerException.
Ca fonctionnera en décalant l'ordre des instructions de manière à avoir l'initialisation en premier comme ceci :
public Splash() {
initComponents();
Thread monthread = new Thread(new MonRunnable());
monthread.start();
}
Après, c'est le code de ce splash est très moche, mais j'imagine qu'une bonne partie a été généré automatiquement, ceci expliquant cela...