Error NoClassDefFoundError When converting .xls to .xlsx

0

I have an Error wanting to Convert this file with a method of the following class:

public class ProcesaArchivo {
UtilArchivo util = new UtilArchivo();
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
String fileCodigo = s + "/codificacion_";
String fileCodigoLV = s + "/codificacion_LV.csv";
Map<String, String> codigosMap = new HashMap<String, String>();

public ProcesaArchivo() {
    //
}

public String procesaLibro(String nomArchivo, String dirSalida,int año, String mes, String tipoLibro)
        throws FileNotFoundException, IOException{

    List cellDataList = new ArrayList();
    try {
        FileInputStream fis = new FileInputStream((nomArchivo));
        XSSFWorkbook wBook = new XSSFWorkbook(fis);// <------ Linea en Conflicto
        XSSFSheet hssfSheet = wBook.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 ex) {
        return "ERROR: Formato de archivo no valido: " + ex.getMessage();
    }
    if(tipoLibro.equals("LC")) {
        return escribeLibroCompra(cellDataList,dirSalida,año,mes,tipoLibro);
    } else {
        return escribeLibroVenta(cellDataList,dirSalida,año,mes,tipoLibro);
    }
}

private String escribeLibroVenta(List cellDataList, String dirSalida, int año, String mes, String tipoLibro) throws IOException {
    String outputFile = dirSalida + "/" + tipoLibro  + "_" + mes +  año  + "_" + Calendar.getInstance().getTimeInMillis() + ".csv";
    String encCompra =  "TipoLibro;TipoDoc;NroDoc;FechaDoc;Anulado;RutDoc;RazonSoc;MontoNeto;MontoExe;MontoIVA;TasaImp;MntTotal";

    try {
        ArrayList filas = new ArrayList();
        ArrayList celdas = new ArrayList();

        //pregunta si existe el archivo scv de compra o venta
        boolean alreadyExists = new File(outputFile).exists();
        if(alreadyExists) {
            File archivoLibro = new File(outputFile);
            archivoLibro.delete();
        }

        CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), '\t');
        csvOutput.write(encCompra);
        csvOutput.endRecord();
        for (int i = 3; i < cellDataList.size(); i++) {
            List cellTempList = (List) cellDataList.get(i);
            for (int j = 0; j < cellTempList.size(); j++) {
                XSSFCell hssfCell = (XSSFCell) cellTempList.get(j);
                celdas.add(hssfCell.toString());
            }
            filas.add(celdas);
            celdas = new ArrayList();
        }

        int salida = 0;
        for(int x = 0; x < filas.size() ; x++) {
            ArrayList fila = (ArrayList) filas.get(x);
            if(fila.size() < 9 ){
                continue;
            }
            if(fila.get(0).toString().toLowerCase().contains("cuadro")){
                salida = 1;
                break;
            }
            if(!fila.get(0).toString().toLowerCase().contains("total")) {
                Date fecha = new SimpleDateFormat("dd-MMM-yyyy", new Locale("es", "CL")).parse(fila.get(0).toString());
                String fechaDoc = new SimpleDateFormat("dd-MM-yyyy").format(fecha);
                String razonSoc = cortaTexto(fila.get(1).toString(),45);
                String rutDoc = fila.get(2).toString();
                String nDoc = getQuitaMontoCeros(fila.get(3).toString());
                String codDoc = fila.get(4).toString().split("-")[0];

                double num = Double.parseDouble(fila.get(6).toString());
                long numero = (long)num;
                String netoAfecto = getQuitaNegativo(numero + "");

                double num2 = Double.parseDouble(fila.get(7).toString());
                long numero2 = (long)num2;
                String iva = getQuitaNegativo(numero2 + "");
                if(iva.equals("0"))
                    iva = "0";
                double num1 = Double.parseDouble(fila.get(8).toString());
                long numero1 = (long)num1;
                String netoExcento = getQuitaNegativo(numero1 + "");

                double num4 = Double.parseDouble(fila.get(10).toString());
                long numero4 = (long)num4;
                String total = getQuitaNegativo(numero4 + "");
                String tasaImp = (iva.trim().equals("")) ? "0" : "19";
                String filaString = "V;" + codDoc + ";" + nDoc + ";" + fechaDoc + ";0;" + rutDoc + ";" + razonSoc + ";" + netoAfecto 
                    + ";" + netoExcento + ";0;" + iva + ";" + tasaImp + ";" + total;

                csvOutput.write(filaString);
                csvOutput.endRecord();
            }
            if(salida == 1) break;
        }

        csvOutput.close();
    } catch (Exception e) {
        return "ERROR: " + e.getMessage();
    }
    return "Se ha creado el archivo correctamente: " + outputFile;
}

private String escribeLibroCompra(List cellDataList, String dirSalida, int año, String mes, String tipoLibro) throws IOException {
    String outputFile = dirSalida + "/" + tipoLibro +  "_" + mes +  año  + "_" + Calendar.getInstance().getTimeInMillis() + ".csv";
    String encCompra =  "TipoLibro;TipoDoc;NroDoc;FechaDoc;Anulado;RutDoc;RazonSoc;MontoNeto;MontoExe;MontoIVA;TasaImp;MontoImpAdd28"
            + ";MntIVANoRec;CodIVANoRec;MntTotal";
    try {
        ArrayList filas = new ArrayList();
        ArrayList celdas = new ArrayList();

        //pregunta si existe el archivo scv de compra o venta
        boolean alreadyExists = new File(outputFile).exists();
        if(alreadyExists) {
            File archivoLibro = new File(outputFile);
            archivoLibro.delete();
        }

        CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), '\t');
        csvOutput.write(encCompra);
        csvOutput.endRecord();
        for (int i = 2; i < cellDataList.size(); i++) {
            List cellTempList = (List) cellDataList.get(i);
            for (int j = 0; j < cellTempList.size(); j++) {
                XSSFCell hssfCell = (XSSFCell) cellTempList.get(j);
                celdas.add(hssfCell.toString());
            }
            filas.add(celdas);
            celdas = new ArrayList();
        }

        int salida = 0;
        for(int x = 0; x < filas.size() ; x++) {
            ArrayList fila = (ArrayList) filas.get(x);
            if(fila.get(0).toString().toLowerCase().contains("cuadro")) {
                salida = 1;
                break;
            }
            if(!fila.get(0).toString().toLowerCase().contains("total")) {
                Date fecha = new SimpleDateFormat("dd-MMM-yyyy", new Locale("es", "CL")).parse(fila.get(0).toString());
                String fechaDoc = new SimpleDateFormat("dd-MM-yyyy").format(fecha);
                String razonSoc = cortaTexto(fila.get(1).toString(),45);
                String rutDoc = fila.get(2).toString();
                String nDoc = getQuitaMontoCeros(fila.get(3).toString());
                String codDoc = fila.get(4).toString().split("-")[0];

                double num = Double.parseDouble(fila.get(6).toString());
                long numero = (long)num;
                String netoAfecto = getQuitaNegativo(numero + "");
                double num1 = Double.parseDouble(fila.get(7).toString());
                long numero1 = (long)num1;
                String netoExcento = getQuitaNegativo(numero1 + "");

                double num2 = Double.parseDouble(fila.get(8).toString());
                long numero2 = (long)num2;
                String iva = getQuitaNegativo(numero2 + "");
                if(iva.equals("0"))
                    iva = "0";

                double num3 = Double.parseDouble(fila.get(9).toString());
                long numero3 = (long)num3;
                String impEspecifico = getQuitaNegativo(numero3 + "");
                if(impEspecifico.equals("0"))
                    impEspecifico = "";

                double num4 = Double.parseDouble(fila.get(10).toString());
                long numero4 = (long)num4;
                String total = getQuitaNegativo(numero4 + "");

                String tasaImp = (iva.trim().equals("")) ? "0" : "19";
                String filaString =  "C;" + codDoc + ";" + nDoc + ";" + fechaDoc + ";;" + rutDoc + ";" + razonSoc + ";" + netoAfecto 
                    + ";" + netoExcento + ";" + iva + ";" + tasaImp + ";" + impEspecifico + ";;;" + total;

                csvOutput.write(filaString);
                csvOutput.endRecord();
            }
            if(salida == 1) break;
        }

        csvOutput.close();
    } catch (Exception e) {
        return "ERROR: " + e.getMessage();
    }
    return "Se ha creado el archivo correctamente: " + outputFile;
}

public String getQuitaMontoCeros(String sMonto){
    for(int x = 0 ; x < sMonto.length() ; x++){
        String a = sMonto.substring(x, x + 1);
        if(!a.equals("0")){
            return sMonto.substring(x);
        }
    }
    return "";
}

public String getQuitaNegativo(String sMonto){
    if(sMonto.contains("-")){
        return sMonto.substring(1);
    }
    return sMonto;
}

public String cortaTexto(String sTexto, int nLargoMax) {
    sTexto = sTexto.replace("¥", "Ñ");
    if (sTexto != null && sTexto.length() > nLargoMax) {
        sTexto = sTexto.substring(0, nLargoMax);
    }
    return sTexto;
}

}

And I have the following error:

    C:\Users\cons00\Desktop\Soportes\Pucobre\respaldo\librocomprasabril2016.xlsx
C:\Users\cons00\Desktop
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
    at bcn.pucobre.controlador.ProcesaArchivo.procesaLibro(ProcesaArchivo.java:48)
    at bcn.pucobre.vista.PanelConector.jButton4ActionPerformed(PanelConector.java:308)
    at bcn.pucobre.vista.PanelConector.access$400(PanelConector.java:15)
    at bcn.pucobre.vista.PanelConector$5.actionPerformed(PanelConector.java:199)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6516)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6281)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4872)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
    at java.awt.EventQueue.access$300(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:706)
    at java.awt.EventQueue$3.run(EventQueue.java:704)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.awt.EventQueue$4.run(EventQueue.java:718)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections4.ListValuedMap
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 40 more

the first two lines are a print of the File and Output Directory variables

    
asked by Felipe Inostroza 14.12.2016 в 18:40
source

1 answer

1

This error appears in your project, one of the classes you use (or depend on) in this case ListValuedMap is present within your project at compile time but not at runtime. As you are told, you must make sure that you import all the jar of the classes on which your library depends.

You can download this library from here

On the answer of this question in Stack over flow in English, they also explain to you, certain exceptions that you must control to correctly identify the error, they also explain to you that the error is due. So when you receive the exception you can better verify the error.

    
answered by 14.12.2016 в 21:27