Impossibeulman
Messages postés32Date d'inscriptionjeudi 7 février 2008StatutMembreDernière intervention25 août 2008
-
29 juil. 2008 à 17:09
Impossibeulman
Messages postés32Date d'inscriptionjeudi 7 février 2008StatutMembreDernière intervention25 août 2008
-
4 août 2008 à 09:48
Bonjours.
Donc voila... Je cherche a récupérer des données de type string (text) dans un fichier XLS a partir d'une apli JAVA.
Mais voila... J'ai un message d'erreur comme quoi l'ouverture du fichier xls a échoué...
Pour infos j'utilise la librairie jxl.
Voila la bride de code la ou sa ne marche pas :
// #######################################################################
public void generer(){
try{
WritableWorkbook workbook = Workbook.createWorkbook(new File(sDirectory));
Sheet sheet = workbook.getSheet(2);
Cell b = sheet.getCell(0,2);
if (b.getType() == CellType.LABEL)
{
LabelCell lc = (LabelCell) b;
a = lc.getString();
}
workbook.close();
jLabel1.setText("Test: " + b);
/*jLabel1.setText("Génération terminer avec succès " + b + " lignes générer.");*/
jButton4.setEnabled(true);
jButton2.setEnabled(false);
jButton3.setEnabled(false);}
Et voici l'erreur que me retourne "catch (Exception e)"
:
java.lang.NullPointerException
at java.io.FileOutputStream.(Unknown Source)
at java.io.FileOutputStream.(Unknown Source)
at jxl.Workbook.createWorkbook(Workbook.java:301)
at jxl.Workbook.createWorkbook(Workbook.java:286)
at Apli.SwingApli.generer(SwingApli.java:250)
at Apli.SwingApli$6.jButton3_clic(SwingApli.java:156)
at Apli.SwingApli$6.actionPerformed(SwingApli.java:155)
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.Window.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)
Donc semblerais que le souci viens du faite que sa trouve pas le fichier...
Sa fait seulement 1 mois que j'ai commencer le java, merci d'avent pour votre aide,
quel qu'il soit...
De plus il ne me reste plus beaucoup de temps pour réaliser mon mini_projet...
Et voici l'erreur que me retourne "catch (Exception e)"
:
java.lang.NullPointerException
at java.io.FileOutputStream.(Unknown Source)
at java.io.FileOutputStream.(Unknown Source)
at jxl.Workbook.createWorkbook(Workbook.java:301)
at jxl.Workbook.createWorkbook(Workbook.java:286)
at Apli.SwingApli.generer(SwingApli.java:250)
at Apli.SwingApli$6.jButton3_clic(SwingApli.java:156)
at Apli.SwingApli$6.actionPerformed(SwingApli.java:155)
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.Window.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)
Donc semblerais que le souci viens du faite que sa trouve pas le fichier...
Sa fait seulement 1 mois que j'ai commencer le java, merci d'avent pour votre aide,
quel qu'il soit...
De plus il ne me reste plus beaucoup de temps pour réaliser mon mini_projet...
indiana_jules
Messages postés750Date d'inscriptionmardi 9 mars 2004StatutMembreDernière intervention23 décembre 200822 30 juil. 2008 à 13:41
Salut,
Lis bien l'erreur retournée. Que dit-elle ? Qu'un "NullPointerException" a été levée. Autrement dit, cela ne vient pas du fait que le fichier lui est inconnu, mais qu'une variable de ton programme n'est pas iniatilisée alors que le programme doit faire une opération dessus.
Or quand on regarde ton code, on a "WritableWorkbook source = Workbook.createWorkbook(fpath1);
" avec aucune initialisation de la variable fpath1 de type File
Du coup, je te conseille de faire cela:
Impossibeulman
Messages postés32Date d'inscriptionjeudi 7 février 2008StatutMembreDernière intervention25 août 2008 30 juil. 2008 à 17:31
Sa ne semble pas marcher ...
Erreur:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Apli.SwingApli.OpenExcel(SwingApli.java:235)
at Apli.SwingApli$4.jButton1_clic(SwingApli.java:142)
at Apli.SwingApli$4.actionPerformed(SwingApli.java:141)
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.Window.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)
indiana_jules
Messages postés750Date d'inscriptionmardi 9 mars 2004StatutMembreDernière intervention23 décembre 200822 30 juil. 2008 à 20:02
A quelle ligne de ton code cela correspond-t-il ? : at Apli.SwingApli.OpenExcel(SwingApli.java:235)
Parce que l'erreur est la même, tu utilises une variable non initialisée (PS: évite au plus le static: il faut vraiement se servir de ce mot clé uniquement pour les constantes et pour les singleton, car sinon, cela peut amener à des erreurs)
Impossibeulman
Messages postés32Date d'inscriptionjeudi 7 février 2008StatutMembreDernière intervention25 août 2008 31 juil. 2008 à 17:00
Je crois que mon code est obsolète...
Si tu devait chercher a Ouvrir un fichier xls avec une OpenDialog , qui permet de savoir ou se trouve le fichier a exploiter.
(exemple c:/toto/tata/le_fichier.xls)
Puis
(après l'appui sur un bouton "Générer"), sa ouvre le fichier exel (en processus cacher),affin de faire plusieurs opération comme compter les
lignes, récupérer des données a stoker dans un tableau etc...