CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2021
    Posts
    3

    NoClassDefFoundError trying to read Excel File

    Wrote this program in Eclipse. DOwnloaded POI 5.0.0 and added it to library by Project->Properties->Java Build Path->Libraries->Added poi-5.0.0.jar and poi-ooxml-5.0.0.jar under classPath. I then get errr NoClassDefFoundError from this line:

    HTML Code:
    workbook = new XSSFWorkbook(excelBIS);
    My entire code:
    HTML Code:
    		JButton btnBrowse = new JButton("Browse File");
    		btnBrowse.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				//Definitions
    
    	        	    
    				//=========Action here==========
    				File excelFile;
    		        FileInputStream excelFIS = null;
    		        BufferedInputStream excelBIS = null;
    		        XSSFWorkbook workbook=null;
    		        
    		        //Default Path
    		        String defaultPath = "C:\\Users\\Philip Chen\\Documents\\dermaGrapher.xlsx";
    		        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());
    		                }
    		            }
    		        	
    		        }
    		        //End of function
    			}
    		});
    Any help is appreciated! I am desperate, Thanks!

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: NoClassDefFoundError trying to read Excel File

    Please copy the full text of the error message and paste it here.

    Is the missing class in a jar file that is on the classpath when the program is executed.

    Also posted here: https://www.javaprogrammingforums.co...tml#post172148
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured