0

I have been working on a project for work for the past week and I am stuck because of an error I keep getting. I was wondering if anyone could help me.

I have attached the two files I have created and the errors I am receiving. If anyone can tell me how to fix the error it would be greatly appreciated

I am using eclipse and have attached all of the recent jar files (xmlbeans2.6, poi-scratchpad 3.13beta, poi-ooxml-schemas 3.13beta, poi-ooxml-3.13beta and poi-3.13 beta)

The first class creates a interface that the user can interact with. First you open an excel file. Then by hitting the categorize button it should call the second class. The second class will read through the excel file and display its content. As of right now if I change the call function to the readxlsfile function it works perfectly. The problem appears when I try to call the readxlsxfile. I get the below error

Also if possible could anyone help me figure out a way to automatically choose the right function depending on which excel file picked.

public class RedoApplication extends JFrame{

private String directory;
private JFileChooser choose;
public RedoAPP RApp;
public File savefile;

public void setDirectory(String d)
{
    this.directory = d;
}

public String getDirectory()
{
    return this.directory;
}
private RedoApplication()
{
    super("Redo Categorization");
    setSize(750, 600);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container c = getContentPane();

    c.setLayout(null);

    final JTextArea instructionBar = new JTextArea(""
            + "REQUIREMENTS:\n"
            + "* Selected Excel(.xlsx) file should be CLOSED when executing\n"
            + "* 1ST WORKSHEET HAS TO BE THE RAW DATA\n\n"
            + "RECOMMENDATIONS:\n"
            + "Best if only HA or DTV products are in the raw data.\n\n"
            + "INSTRUCTION:\n1. Choose raw Excl file(only .xlsx)\n2. Do not alter default column names, but order doesn't matter\n\n"
            + "WHEN CATEGORIZED:\n1. The file you have selected will have categorization in the last column\n2. Statistics will be in last worksheet\n\n"
            + "ABOUT LOGIC FILE:\n"
            + "Logic file has to be in the same folder\n"
            + "The workbook(tab) order and name should stay the same.\n"
            + "Keyword sheet's name of keywords list should is also set.");

    instructionBar.setBounds(20, 90, 220, 450);
    instructionBar.setLineWrap(true);
    Font font = new Font("ARIAL", Font.BOLD, 12);
    instructionBar.setFont(font);       
    instructionBar.setWrapStyleWord(true); 
    instructionBar.setEditable(false);

    JLabel label = new JLabel();

    ImageIcon icon = new ImageIcon("c:/users....");
    label.setIcon(icon);
    label.setBounds(10, 10, 300, 50);

    JButton openButton = new JButton("Choose file");
    openButton.setBounds(330, 90, 100, 30);

    final JLabel statusBar = new JLabel("Accepting file...", SwingConstants.CENTER);
    statusBar.setBounds(280, 140, 200, 30);

    final JProgressBar progressBar = new JProgressBar();
    progressBar.setBounds(280, 340, 150, 20);
    progressBar.setStringPainted(true);

    final BlinkLabel bl = new BlinkLabel("Standby");
    bl.setBounds(310, 270, 150, 100);
    bl.setBlinking(false);

    final JButton catButton = new JButton("Categorize");        
    catButton.setBounds(330, 190, 100, 100);

    Font font1 = new Font("ARIAL", Font.BOLD, 14);
    JLabel analysisBar = new JLabel("Quick analysis:");
    analysisBar.setBounds(480, 40, 200, 100);
    analysisBar.setFont(font1);
    analysisBar.setForeground(Color.BLUE);

    final JTextArea analysisArea = new JTextArea("No analysis yet.");
    analysisArea.setBounds(480, 100, 250, 200);
    analysisArea.setFont(font1);
    analysisArea.setEditable(false);

    final ButtonGroup g = new ButtonGroup();

    JRadioButton rb1 = new JRadioButton("DTV", true);
    rb1.setActionCommand("DTV");
    rb1.setBounds(330, 40, 60, 30);
    rb1.setBackground(Color.WHITE);

    JRadioButton rb2 = new JRadioButton("HA", false);
    rb2.setActionCommand("HA");
    rb2.setBounds(390, 40, 60, 30);
    rb2.setBackground(Color.WHITE);



    openButton.addActionListener
    (
            new ActionListener() 
            {
                public void actionPerformed(ActionEvent ae) 
                {

                    String[] excel = new String[] { "xlsx" };

                    choose = new JFileChooser("C:\\Users\\.....");

                    choose.addChoosableFileFilter(new SimpleFileFilter(excel,"Excel(2007-) (*.xlsx)"));

                    choose.setAcceptAllFileFilterUsed(true);

                    //InputFile = choose.getSelectedFile();

                    int option = choose.showOpenDialog(RedoApplication.this);

                    if (option == JFileChooser.APPROVE_OPTION) 
                    {
                        if (choose.getSelectedFile() != null)
                        {
                            statusBar.setText(choose.getSelectedFile().getName());

                            setDirectory(choose.getSelectedFile().getAbsolutePath());
                        }
                    } 
                    else 
                    {
                        statusBar.setText("No file selected");
                    }

                }
            }
        );

    catButton.addActionListener
    (
            new ActionListener() 
            {
                public void actionPerformed(ActionEvent ae) 
                {
                    System.out.println(g.getSelection().getActionCommand());
                    if(g.getSelection().getActionCommand().equals("DTV"))
                    {
                        File savefile = choose.getSelectedFile();
                        RedoAPP RApp = new RedoAPP();
                        RApp.readxlsxfile(savefile);


                    }
                }
            }
    );

    ActionListener alRadio = new ActionListener() 
     {
            public void actionPerformed(ActionEvent e) 
            {

            }
     };     
            c.add(instructionBar);
            c.add(openButton);
            c.add(statusBar);
            c.add(catButton);
            c.add(analysisBar);
            c.add(analysisArea);

            c.add(label);
            getContentPane().setBackground(Color.WHITE);

            rb1.addActionListener(alRadio);
            rb2.addActionListener(alRadio);
            g.add(rb1);
            g.add(rb2);
            c.add(rb1);
            c.add(rb2);
            c.add(progressBar);
            c.add(bl);

            setVisible(true);
}




public static void main(String args[]) 
{

    RedoApplication Redo = new RedoApplication();


}}

public class RedoAPP {

public void readxlsfile(File savefile)
{
    try
    {
        FileInputStream file = new FileInputStream(savefile);

        //Create Workbook
        HSSFWorkbook workbook = new HSSFWorkbook(file);
        //Get first sheet
        HSSFSheet sheet = workbook.getSheetAt(0);
        //Go through each row one by one
        Iterator<Row> rowIterator = sheet.rowIterator();

        while (rowIterator.hasNext())
        {
            Row row = rowIterator.next();
            //Iterate through each column of each row
            Iterator<Cell> cellIterator = row.cellIterator();

            while (cellIterator.hasNext())
            {
                Cell cell = cellIterator.next();
                //check cell type and format accordingly
                switch (cell.getCellType())
                {
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "  ");
                    break;
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getRichStringCellValue() + "  ");
                    break;
                }
            }
            System.out.println("");
        }
        file.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}


public void readxlsxfile(File savefile)
{
    try
    {
        FileInputStream file1 = new FileInputStream(savefile);

        XSSFWorkbook workbook = new XSSFWorkbook(file1);
        XSSFSheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.rowIterator();

        while (rowIterator.hasNext())
        {
            Row row = rowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();

            while (cellIterator.hasNext())
            {
                Cell cell = cellIterator.next();

                switch (cell.getCellType())
                {
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "  ");
                    break;
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getRichStringCellValue() + "  ");
                    break;
                }
            }
            System.out.println("");
        }
        file1.close();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

}

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: org.apache.poi.util.POILogger.log(I[Ljava/lang/Object;)V at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313) at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.(PackageRelationshipCollection.java:163) at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.(PackageRelationshipCollection.java:131) at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:561) at org.apache.poi.openxml4j.opc.PackagePart.(PackagePart.java:109) at org.apache.poi.openxml4j.opc.PackagePart.(PackagePart.java:80) at org.apache.poi.openxml4j.opc.PackagePart.(PackagePart.java:125) at org.apache.poi.openxml4j.opc.ZipPackagePart.(ZipPackagePart.java:78) at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:245) at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275) at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:274) at samsung.RedoAPP.readxlsxfile(RedoAPP.java:73) at samsung.RedoApplication$2.actionPerformed(RedoApplication.java:176) 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.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(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)

5
  • Please provide enough information for somebody to replicate the problem. You haven't provided any information about your configuration, what versions of POI, etc. Please don't just spam code at us but take the time to think of what information would be helpful. Reproducibility is key. Commented Aug 3, 2015 at 18:18
  • Having said that, I observe that org.apache.poi.openxml4j.opc.PackageRelationshipCollection is in org.apache.poi:poi-ooxml while org.apache.poi.util.POILogger is in org.apache.poi:poi. Are you using the same version of these two libraries? Commented Aug 3, 2015 at 18:20
  • I apologize, this is my very first post. I don't know what information was needed. Commented Aug 3, 2015 at 18:32
  • But in reference to your question I am using the same version. They are both 3.13 beta Commented Aug 3, 2015 at 18:33
  • Looks like you have old and new POI jars on your classpath, which is explicitly not supported! What happens if you delete your old POI jars, leaving just the latest ones? Commented Aug 3, 2015 at 23:25

1 Answer 1

3

I believe you have configured it to use the same version of POI, but I still think an old version is leaking into your classpath from somewhere. The below code is taken from the POI FAQs; please be absolutely certain that all three outputs below are what you expect.

ClassLoader classloader =
   org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
             "org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("POI Core came from " + path);

classloader = org.apache.poi.POIXMLDocument.class.getClassLoader();
res = classloader.getResource("org/apache/poi/POIXMLDocument.class");
path = res.getPath();
System.out.println("POI OOXML came from " + path);

classloader = org.apache.poi.hslf.HSLFSlideShow.class.getClassLoader();
res = classloader.getResource("org/apache/poi/hslf/HSLFSlideShow.class");
path = res.getPath();
System.out.println("POI Scratchpad came from " + path);
Sign up to request clarification or add additional context in comments.

2 Comments

Also, just IMHO, you may want to reconsider your decision to use a beta version of the library...
You were right. Old versions were being pointed to. I corrected the jar files and it works perfectly. I appreciate it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.