Probleme avec java et "Exception in thread .&

Fermé
Friday_XIII - 4 févr. 2009 à 17:52
 Friday_XIII - 5 févr. 2009 à 17:45
Bonjour,
je dois réaliser une applet java reliée à une base de donnée de type Mysql.
Je me suis renseigné sur le net pour le jdbc et avec Netbeans, voici ce que j'ai produit (il manque juste la partie graphique) :

import java.lang.*;
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

public class lePendu extends JApplet {

//partie utilisation
private Vector Mots; // liste des mots où on va choisir celui à deviner
private char[] Mot; // mot à deviner
private char[] motTranspose; // mot à deviner : mais les lettres sont remplacées par des tirets
private int Longueur; // longueur du mot à deviner
private int nombreCoups; // nombre de coups dispo
private boolean fini=false;// permet de savoir si on a deviné toutes les lettres du mot <=> permet de savoir si on a gagné (ou pas ...)
private boolean etat=false;// si la lettre se trouve dans le mot (false : non ; true : oui)
private String temp;
private String compteur;
private String style = new String("no style");

public void init() {
initialisation();
}//init

public static Connection creerConnection() {
try {
MysqlDataSource mds = new MysqlDataSource();
mds.setPortNumber(3306);
mds.setUser(******); => nom de la base
mds.setPassword(*****);
mds.setServerName("sql.free.fr");
mds.setDatabaseName(******);
return(mds.getConnection());
}
catch(Exception e) {
System.out.println("erreur de connection ....");
return null;
}
}
void initialisation(){
//connection
try {
Connection con;
con=creerConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT nomArtiste FROM Artiste");

Vector Mots = new Vector(10,5);
while(rs.next()){
String s = rs.getString("nomArtiste");
Mots.add(s);
}
stmt.close();
con.close();

String mot=tirageMots(Mots);// on tire un mot au sort*/
Mot=mot.toCharArray();
Longueur=Mot.length;
motTranspose = new char[Mot.length]; // on transpose le mot en tirets
for (int i=0;i<Longueur;i++) {
if (Mot[i]!=' ')
motTranspose[i]='-';
else
motTranspose[i]=' ';
}//for
nombreCoups=10; // on initialise le nombre de coups à 10.
temp = new String(motTranspose);
JMot.setText(temp);
JTexte.setVisible(true);
JSaisie.setVisible(true);
JCompteur.setText(compteur);
JDessin.setIcon(new ImageIcon(figure0));
fini=false;
JGagne.setVisible(false);
JPerdu.setVisible(false);
JReponse.setVisible(false);
}//try
catch(Exception e2) {
JOptionPane j2 = new JOptionPane();
j2.showMessageDialog(null,"ClassNotFoundException : \n"+e2.getMessage(),"erreur",JOptionPane.ERROR_MESSAGE);
}

}//initialisation

public String tirageMots(Vector mots) {
Random r=new Random ();
int var=Math.abs(r.nextInt()%(Mots.size() ) );
String mot=(String)Mots.get(var);
return mot;
}//tirageMot

public char[] getMot() {
return Mot;
}//getMot

public int getLongueur() {
return Longueur;
}//getLongueur
}//Jeu

j'ai réglé le classpath en incluant l'archive jar comme il le fallait (je l'ai mise dans le dossier créé par Netbeans. Aucune erreur à la compilation, et quand j'exécute, voici le message d'erreur :

Exception in thread "AWT-EventQueue-2" java.lang.NoClassDefFoundError: com/mysql/jdbc/jdbc2/optional/MysqlDataSource
at lePendu.creerConnection(lePendu.java:281)
at lePendu.initialisation(lePendu.java:300)
at lePendu$PartieListener.actionPerformed(lePendu.java:464)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(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)
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 27 more
Caused by: java.io.FileNotFoundException: G:\IUT\Projet 2eme année\Pendu\build\classes\com\mysql\jdbc\jdbc2\optional\MysqlDataSource.class (Le chemin d'accès spécifié est introuvable)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 31 more


j'ai cherché sur internet et pas moyen de trouver d'où vient l'erreur .... je pense que je devrais configurer Netbeans mais je sais pas quoi ....
Pourriez vous m'aider s'il vous plait ?
A voir également:

1 réponse

c'est parce que le code est trop lourd, ou que personne n'a trouvé que personne n'a rien écris ? XD
4