Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6702029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:00:17+00:00 2026-05-26T07:00:17+00:00

i am a barely new to the java (was always on c# before) and

  • 0

i am a barely new to the java (was always on c# before) and need to create a swing application where i need to read a data from xls file. So i use jXL.

I have a class, which returns name of a first sheet from excel file, choosen in jFileChooser. Here is the code:

import java.io.File;
import jxl.Sheet;
import jxl.Workbook;

public class ExcelObject
{
    private String filename = null;
    private Workbook wb = null;
    private Sheet sheet = null;

    public ExcelObject(String f) 
    {
        filename = f;
    }

    public String getSheetName()
    {
        String sheet_name = null;

        try
        {
            wb = Workbook.getWorkbook(new File(filename));
            sheet = wb.getSheet(0);
            sheet_name = sheet.getName();
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        finally
        {
            wb.close();
        }

        return sheet_name;
    }

}   

in the program call looks like :

ExcelObject ex = new ExcelObject(filename);
String s = ex.getSheetName();
lblReport.setText(s);

So the issue is : when ran in the eclipse (3.4.2) i am getting a correct value, when jar is compiled, NO VALUE IS RETURNED! I mean lblReport is empty, with no exceptions and warnings.

Keep in mind : all other external jars work fine.

I tried a lot of things but none is working.

Also, if i do something like

                            ExcelObject ex = new ExcelObject(filename);
                            String s = ex.getSheetName();
//                          lblReportRun.setText(s);

                            lblReportRun.setText("Test");
                            lblAnyOtherLabel.setText("Test");

no text is displayed in the labels either, in compiled jar, and fine in eclipse.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:00:17+00:00Added an answer on May 26, 2026 at 7:00 am

    This is probably because if some exception occurs when opening the workbook, you catch it, print the stack trace, and then close the workbook in the finally block. But since an exception occurred when calling Workbook.getWorkbook, the wb variable is still null, and you’re trying to invoke close on it. So a NullPointerException happens while in the finally block.

    Watch your console, you must have some exception popping up.

    Also, note that fileName should be the only instance variable of your class, that Java variable normally don’t contain underscores and use camelCase, and thet the fileName variable should be of type File, rather than String : you get a File from the file chooser, transform it into a string, and then transform it back to a File.

    Another possibility, since it works in Eclipse and not when run externally, is that you forgot to put the jXL jar in the classpath, which causes some ClassNotFoundException when trying to use the ExcelObject class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read a file structured like this: 01000 00030 00500 03000 00020
I'd like to create a dynamic Multidimensional ArrayList that reads from a text file
I need to separate multiframe tiff files, and use the following method: public static
=== about me === I'm new to android development and barely able to speak
I'm new to linux kernel and could barely understand how to debug kernel panics.
I'm starting to implement a simple daemon that basically fetches a file from an
I have a TODO file that I load emacs up to use 90% of
I want (barely computer literate) people to easily submit a large number of files
I could barely find a reasonable title that would explain my issue, let alone
Morning y'all This is probably an easy one but I barely got any sleep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.