Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: NoClassDefFoundError while reading Excel File (Apache POI 5.0.0)

  1. #1
    Junior Member
    Join Date
    Jul 2021
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default NoClassDefFoundError while reading Excel File (Apache POI 5.0.0)

    I am trying to read an excel file into a JTable. I gotten this NoClassDefFoundError at this line:
    XSSFWorkbook excelJTableImport = new XSSFWorkbook(excelBIS);

    I'm using Apache POI 5.0.0.

    Code of table definition:
    		table = new JTable();
    		scrollPane.setViewportView(table);
    		table.setModel(new DefaultTableModel(
    			new Object[][] {
    			},
    			new String[] {
    				"User Name", "Record Date", "Final Score", "Oil Average", "Hydration Average", "Melanin Average", "Oxygen Average", "Redness Average"
    			}
    		) {
    			Class[] columnTypes = new Class[] {
    				String.class, String.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class
    			};
    			public Class getColumnClass(int columnIndex) {
    				return columnTypes[columnIndex];
    			}
    		});

    Code when browse button is selected:
    		JButton btnBrowse = new JButton("Browse File");
     
    		btnBrowse.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				//Definitions
    				 DefaultTableModel model=null;
    	        	    String userName = "";
    	        	    String recordDate = "";
    	        	    Integer finalScore = 0;
    	        	    Integer oilAverage = 0;
    	        	    Integer hydrationAverage = 0;
    	        	    Integer melaninAverage = 0;
    	        	    Integer oxygenAverage = 0;
     
    				//=========Action here==========
    				File excelFile;
    		        FileInputStream excelFIS = null;
    		        BufferedInputStream excelBIS = null;
    		        XSSFWorkbook workbook=null;
     
    		        //Default Path
    		        String defaultPath = "C:\\";
    		        JFileChooser fileChooser=new JFileChooser(defaultPath);
    		        int excelChooser=fileChooser.showOpenDialog(null);
     
    		        //Open Button Clicked
    		        if(excelChooser==JFileChooser.APPROVE_OPTION)
    		        {
    		        	try
    		        	{
    		        		excelFile=fileChooser.getSelectedFile();
    			        	excelFIS=new FileInputStream(excelFile);
    			        	excelBIS=new BufferedInputStream(excelFIS);
     
    			        	workbook = new XSSFWorkbook(excelBIS);
    			        	XSSFSheet excelSheet = workbook.getSheetAt(0);
     
    			        	//Loop through excel columns and rows
    			        	for(int row=0;row<10;row++)
    			        	{
     
     
     
    			        		XSSFRow excelRow=excelSheet.getRow(row);
     
    			        		XSSFCell excelName = excelRow.getCell(0);
    		                    XSSFCell excelDate = excelRow.getCell(1);
    		                    XSSFCell excelScore = excelRow.getCell(2);
    		                    XSSFCell excelOil = excelRow.getCell(3);
    		                    XSSFCell excelHydration = excelRow.getCell(4);
    		                    XSSFCell excelMelanin = excelRow.getCell(5);
    		                    XSSFCell excelOxygen = excelRow.getCell(6);
    		                    XSSFCell excelRedness = excelRow.getCell(7);
     
    		                    model.addRow(new Object[]{excelName, excelDate, excelScore, excelOil, excelHydration,excelMelanin,excelOxygen,excelRedness});
    			        	}
    		        	}catch(FileNotFoundException ex)
    		        	{
    		        		JOptionPane.showMessageDialog(null, ex.getMessage());
    		        	}catch(IOException ex)
    		        	{
    		        		JOptionPane.showMessageDialog(null, ex.getMessage());
    		        	}finally {
    		                try {
    		                    if (excelFIS != null) {
    		                        excelFIS.close();
    		                    }
    		                    if (excelBIS != null) {
    		                        excelBIS.close();
    		                    }
    		                    if (workbook != null) {
    		                    	workbook.close();
    		                    }
    		                } catch (IOException iOException) {
    		                    JOptionPane.showMessageDialog(null, iOException.getMessage());
    		                }
    		            }
     
    		        }
    			}
    		});

    Additionally, I got a warning at this line
     model.addRow(new Object[]{excelName, excelDate, excelScore, excelOil, excelHydration,excelMelanin,excelOxygen,excelRedness});
    that model can only be null at this location.

    What did I do wrong that caused me the warning and error? How do I fix this?
    Help is appreciated!

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: NoClassDefFoundError while reading Excel File (Apache POI 5.0.0)

    Do you have the jar file that contains the missing class? Is that jar file on the classpath when the code is executed?

    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: NoClassDefFoundError while reading Excel File (Apache POI 5.0.0)

    Also posted here: https://forums.codeguru.com/showthre...40#post2239640
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. A quick fix and some help reading from excel / text file
    By Iantaylora in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 22nd, 2013, 12:53 PM
  2. Reading multiple columns from an excel file using apache poi 3
    By ramachandra469 in forum Java Theory & Questions
    Replies: 1
    Last Post: May 15th, 2013, 11:01 AM
  3. Reading Excel sheet using apache poi 3.8
    By dnessapkota10 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 11th, 2012, 05:42 AM
  4. Creating an Excel file using apache poi
    By mija in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: August 17th, 2012, 05:15 AM
  5. Reading from a Text file & writing to Excel spreadsheets
    By javanooby in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: May 14th, 2012, 12:41 PM

Tags for this Thread