Exception in thread "main" java.lang.NoClassDefFoundError: org / apache / poi / poifs / filesystem / FileMagic

0

I try to read an Excel file to later operate on the values that are immersed in the cells but I get the following error:

"Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/FileMagic"

How can I solve it?

My code is:

package generadorfrecuencia;

import java.io.File;
import java.io.FileInputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


public class GeneradorFrecuencia {

    public GeneradorFrecuencia(File fileName) throws ParseException {
        List cellDataList = new ArrayList();
        try {
            FileInputStream fileInputStream = new FileInputStream(fileName);
            XSSFWorkbook workBook = new XSSFWorkbook(fileInputStream);
            XSSFSheet hssfSheet = workBook.getSheetAt(0);
            Iterator rowIterator = hssfSheet.rowIterator();
            while (rowIterator.hasNext()) {
                XSSFRow hssfRow = (XSSFRow) rowIterator.next();
                Iterator iterator = hssfRow.cellIterator();
                List cellTempList = new ArrayList();

                while (iterator.hasNext()) {
                    XSSFCell hssfCell = (XSSFCell) iterator.next();
                    cellTempList.add(hssfCell);
                }
                cellDataList.add(cellTempList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        Leer(cellDataList);
    }

    public void Leer(List cellDataList) {
        for (int i = 0; i < cellDataList.size(); i++) {
            List cellTempList = (List) cellDataList.get(i);
            for (int j = 0; j < cellTempList.size(); j++) {
                XSSFCell hssfCell = (XSSFCell) cellTempList.get(j);
                String stringCellValue = hssfCell.toString();
                System.out.print(stringCellValue + " ");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) throws ParseException {
        // TODO code application logic here
        File f = new File("asd.xlsx");
        if (f.exists()) {
            GeneradorFrecuencia gf = new GeneradorFrecuencia(f);
        }
    }
}

Error:

    
asked by Jorge 23.10.2018 в 00:42
source

0 answers