Problème de syntaxe : Erreur "java.lang.NullPointerException"
Voila je vous montre une partie simplifiée de mon programme cependant il y a une ou des erreurs que je n'arrive pas à voir ...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
package tests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class CopyOfProgramme_final {
public CopyOfProgramme_final() {
super();
}
public void findFiles(String directoryPath) throws FileNotFoundException, IOException {
File directory = new File(directoryPath);
File[] subfiles = directory.listFiles();
for(int i=0 ; i<subfiles.length; i++){
System.out.println(subfiles[i].getName());
POIFSFileSystem fs =
new POIFSFileSystem(new FileInputStream("C:/test2/"+subfiles[i].getName()));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(1);
for (Iterator<HSSFRow> rit = (Iterator<HSSFRow>)sheet.rowIterator(); rit.hasNext(); ) {
HSSFRow row = rit.next();
HSSFCell cell = row.getCell((short)0);
cell.getNumericCellValue();
HSSFCell cell2 = row.getCell((short)2);
cell2.getStringCellValue();
HSSFCell cell3 = row.getCell((short)3);
cell3.getStringCellValue();
HSSFCell cell4 = row.getCell((short)4);
cell4.getStringCellValue();
HSSFCell cell5 = row.getCell((short)5);
cell5.getStringCellValue();
HSSFCell cell6 = row.getCell((short)6);
cell6.getStringCellValue();
HSSFCell cell7 = row.getCell((short)7);
cell7.getStringCellValue();
HSSFCell cell8 = row.getCell((short)8);
cell8.getDateCellValue();
HSSFCell cell9 = row.getCell((short)9);
cell9.getStringCellValue();
HSSFCell cell10 = row.getCell((short)10);
cell10.getStringCellValue();
HSSFCell cell11 = row.getCell((short)11);
cell11.getStringCellValue();
HSSFCell cell12 = row.getCell((short)12);
cell12.getStringCellValue();
HSSFCell cell13 = row.getCell((short)13);
cell13.getStringCellValue();
HSSFCell cell14 = row.getCell((short)14);
cell14.getStringCellValue();
HSSFCell cell15 = row.getCell((short)15);
cell15.getStringCellValue();
HSSFCell cell16 = row.getCell((short)16);
cell16.getStringCellValue();
HSSFCell cell17 = row.getCell((short)17);
cell17.getStringCellValue();
HSSFCell cell18 = row.getCell((short)18);
cell18.getStringCellValue();
HSSFCell cell19 = row.getCell((short)19);
cell19.getStringCellValue();
HSSFCell cell20 = row.getCell((short)20);
cell20.getDateCellValue();
HSSFCell cell21 = row.getCell((short)21);
cell21.getDateCellValue();
HSSFCell cell22 = row.getCell((short)22);
cell22.getStringCellValue();
HSSFCell cell23 = row.getCell((short)23);
cell23.getDateCellValue();
HSSFCell cell24 = row.getCell((short)24);
cell24.getStringCellValue();
HSSFCell cell25 = row.getCell((short)25);
cell25.getStringCellValue();
HSSFCell cell26 = row.getCell((short)26);
cell26.getStringCellValue();
System.out.println(cell);
}
HSSFSheet sheet2 = wb.getSheetAt(2);
for (Iterator<HSSFRow> rit2 = (Iterator<HSSFRow>)sheet2.rowIterator(); rit2.hasNext(); ) {
HSSFRow row2 = rit2.next();
HSSFCell nom_HDR = row2.getCell((short)1);
nom_HDR.getStringCellValue();
HSSFCell prenom_HDR = row2.getCell((short)2);
prenom_HDR.getStringCellValue();
//HSSFCell matricule_HDR = row.getCell((short)3);
//matricule_HDR.getStringCellValue();
HSSFCell grade_HDR = row2.getCell((short)3);
grade_HDR.getStringCellValue();
HSSFCell HDR_doctorat = row2.getCell((short)6);
HDR_doctorat.getStringCellValue();
HSSFCell etablisement_delivrance = row2.getCell((short)7);
etablisement_delivrance.getStringCellValue();
System.out.println(nom_HDR);
}
}
}
public static void main(String[] args) throws FileNotFoundException, IOException {
CopyOfProgramme_final finder = new CopyOfProgramme_final();
finder.findFiles("C:/test2");
}
} |
L'erreur que me retourne Eclipse :
Exception in thread "main" java.lang.NullPointerException
at tests.CopyOfProgramme_final.findFiles(CopyOfProgramme_final.java:42)
at tests.CopyOfProgramme_final.main(CopyOfProgramme_final.java:118)
Sachant que la ligne 42 est celle ci :
cell.getNumericCellValue();
Sachant que la ligne 118 est celle ci :
finder.findFiles("C:/test2");
Merci de votre aide ...