Je travaille actuellement sur NetBeans IDE 8.2 (version que je dois utiliser pour les cours) et je bosse actuellement sur un projet perso pour m'aider à progresser. Il se trouve que j'ai un soucis avec une de mes classes. Elle a pour but dans un premier temps de créer un fichier Excel que je remplirai par la suite avec les objets des autres classes.
Pour la tester j'ai intégrer un main pour voir si elle fonctionne mais la classe en question me retourne 2 erreurs à la compilation.
La première lors du premier Run :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/util/ArithmeticUtils
at org.apache.poi.poifs.property.RootProperty.setSize(RootProperty.java:59)
at org.apache.poi.poifs.property.DirectoryProperty.<init>(DirectoryProperty.java:52)
at org.apache.poi.poifs.property.RootProperty.<init>(RootProperty.java:31)
at org.apache.poi.poifs.property.PropertyTable.<init>(PropertyTable.java:58)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:102)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:124)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:1373)
at ExcelDataUpdater.exportDataToExcel(ExcelDataUpdater.java:64)
at ExcelDataUpdater.main(ExcelDataUpdater.java:73)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.util.ArithmeticUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more
..\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Le fichier Excel est bien créer mais si je vais l'ouvrir dans le dossier j'ai le message suivant :
" Le format du fichier "TestResultData.xls" ne correspondent pas. Le fichier peux présenter un risque ou avoir été endommagé. Ne l'ouvrez pas, à moins que la source soit fiable. Voulez vous quand même l'ouvrir "
Lors du second Run j'ai :
Exception in thread "main" org.apache.poi.EmptyFileException: The supplied file was empty (zero bytes long)
at org.apache.poi.util.IOUtils.peekFirstNBytes(IOUtils.java:111)
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:206)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:248)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:221)
at ExcelDataUpdater.exportDataToExcel(ExcelDataUpdater.java:33)
at ExcelDataUpdater.main(ExcelDataUpdater.java:73)
..\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Je ne vois vraiment pas comment régler ça parce que je ne vois pas d'où peut venir le problème. J'ai bien ajouté Apache POI à la librairie de mon projet et dans le doute je l'ai même intégré dans le PATH.
Voici le code de ma classe, voyez si vous voyez quelque chose qui m'échappe :
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
public class ExcelDataUpdater {
public static void dataVersExcel(String fileName, String tabName, String[][] data)
throws FileNotFoundException, IOException, EncryptedDocumentException, Exception {
FileInputStream inputStream = null;
Workbook wb;
Sheet sheet = null;
if (!fileName.endsWith(".xls"))
throw new IllegalArgumentException("Format incorrect. Essayer avec un type .xls");
File newFile = new File(fileName);
if (!newFile.exists())
wb = new HSSFWorkbook();
else {
inputStream = new FileInputStream(newFile);
wb = WorkbookFactory.create(inputStream);
}
boolean isSheetFound = false;
for (int i = 0; i < wb.getNumberOfSheets(); i++)
if (wb.getSheetName(i).equals(tabName)) {
sheet = wb.getSheet(tabName);
isSheetFound = true;
}
if (!isSheetFound)
sheet = wb.createSheet(tabName);
Row[] row = new Row[data.length];
Cell[][] cell = new Cell[row.length][];
for (int i = 0; i < row.length; i++) {
row[i] = sheet.createRow(i);
cell[i] = new Cell[data[i].length];
for (int j = 0; j < cell[i].length; j++) {
cell[i][j] = row[i].createCell(j);
cell[i][j].setCellValue(data[i][j]);
}
}
if (inputStream != null)
inputStream.close();
FileOutputStream outputStream = new FileOutputStream(newFile);
wb.write(outputStream);
outputStream.close();
wb.close();
System.out.println("Pas d'erreur à signaler");
}
public static void main(String[] args)
throws EncryptedDocumentException, FileNotFoundException, IOException, Exception {
String data1[][] = { { "A", "B", "C", "D" } };
ExcelDataUpdater.dataVersExcel("TestResultData.xls", "Results1", data1);
String data2[][] = { { "X", "Y", "Z", "W" } };
ExcelDataUpdater.dataVersExcel("TestResultData.xls", "Results2", data2);
}
}
Bonjour, effectivement il me manqué la ligne de commande que tu m'as indiqué et la librairie associé et maintenant ça fonction tout bon
Merci à tous pour vos réponses
[Erreur] NoClassFound /The supplied file was empty
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
PXL Le retro gaming facile Thread sur le forum: https://openclassrooms.com/forum/sujet/retro-pxl
PXL Le retro gaming facile Thread sur le forum: https://openclassrooms.com/forum/sujet/retro-pxl