Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue May 05, 2020 11:34 am

Hi

I'm trying to use spire.xls and I get a null pointer exception on the very first line (Workbook workbook0 = new Workbook();). Thanks for your help.

Code: Select all
public Test(){

Workbook workbook0 = new Workbook();

}


java.lang.NullPointerException
   at com.spire.xls.packages.sprhya.spr  (Unknown Source)
   at com.spire.xls.packages.sprhya.spr (Unknown Source)
   at com.spire.xls.packages.sprhya.spr  (Unknown Source)
   at com.spire.xls.packages.sprhya.<init>(Unknown Source)
   at com.spire.xls.packages.sprnqa.<init>(Unknown Source)
   at com.spire.xls.packages.sprDpa.<init>(Unknown Source)
   at com.spire.xls.core.spreadsheet.XlsWorkbook.<init>(Unknown Source)
   at com.spire.xls.Workbook.<init>(Unknown Source)


javaint123
 
Posts: 1
Joined: Tue May 05, 2020 11:29 am

Wed May 06, 2020 1:46 am

Hello,

Thanks for your inquiry.
I did an initial test with latest Spire.XLS for Java Version:3.4.8 but didn't reproduce your issue. If you are using an older version, please try again with the latest version.
If the issue still happens, to help us further look into it, please share your project with us. You could send it to us(support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri May 15, 2020 10:24 am

Hello,

Greetings from E-iceblue!
How is your issue now? Any feedback will be greatly appreciated!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Jun 26, 2020 12:42 pm

rachel.lei wrote:Hello,

Greetings from E-iceblue!
How is your issue now? Any feedback will be greatly appreciated!

Sincerely,
Rachel
E-iceblue support team



I might encountered the same error before, it mostly because the conflict between spire.xls and other spire package. The error for me is i used spire.pdf and spire.xls, when import spire.pdf package, the error occurred. Hope it help

majunhai
 
Posts: 3
Joined: Fri Jun 26, 2020 12:20 pm

Mon Jun 29, 2020 1:25 am

Hi majunhai,

Thanks for using our products and sharing this information with us.
Yes, our Spire.PDF and Spire.XLS are not compatible. If you want to two or more our products in the same project, you need to use Spire.Office instead to avoid compatibility issues.
If you encounter any problems related to our product in the future, just feel free to contact us.
Have a nice day :D !

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Sat Jul 04, 2020 5:37 pm

Greetings.

I got the same NullPointerException in Workbook constructor. I tried a new Maven project with the only dependency e-iceblue:spire.office.free:3.1.1 and even tried deleting my entire m2 repository before building and running, and it still happens. Assistance will be appreciated.

gabiaxel
 
Posts: 4
Joined: Sat Jul 04, 2020 5:18 pm

Mon Jul 06, 2020 8:27 am

Hi Gabriel,

Thanks for your inquiry.
To help us further look into your issue, please tell us your test environment information, such as your OS information (E.g. Windows 7, 64 bit) and region setting (E.g. China, Chinese). Meanwhile, I'd suggest you test your case with our latest commercial version Spire.Office v3.6.4, since it is more stable than the free version and contains more bug fixes. Looking forward to your response.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Jul 06, 2020 6:49 pm

I'm running on MacOS 10.15.5 and my region and locale are set to US English. The same happens when I replace the dependency with e-iceblue:spire.xls.free:2.2.0 . I did try to switch to e-iceblue:spire.office:3.6.4 , and the constructor call passes fine, but I get an exception on Worksheet.saveToImage() for several spreadsheets I tried, including very simple ones:

Code: Select all
java.lang.NullPointerException
   at java.util.Hashtable.containsKey(Hashtable.java:336)
   at com.spire.office.packages.sprPCA.spr  (Unknown Source)
   at com.spire.office.packages.sprecA.<clinit>(Unknown Source)
   at com.spire.office.packages.sprPCA.spr (Unknown Source)
   at com.spire.office.packages.sprBBA.spr  (Unknown Source)
   at com.spire.office.packages.sprXDA.spr  (Unknown Source)
   at com.spire.office.packages.sprFEA.spr  (Unknown Source)
   at com.spire.office.packages.sprhFA.<init>(Unknown Source)
   at com.spire.office.packages.sprFlA.spr  (Unknown Source)
   at com.spire.office.packages.sprcjC.spr  (Unknown Source)
   at com.spire.office.packages.sprMlA.spr  (Unknown Source)
   at com.spire.office.packages.sprMlA.spr  (Unknown Source)
   at com.spire.office.packages.sprcKA.spr  (Unknown Source)
   at com.spire.xls.core.spreadsheet.XlsWorkbook.spr  (Unknown Source)
   at com.spire.xls.core.spreadsheet.XlsWorkbook.spr  (Unknown Source)
   at com.spire.xls.core.spreadsheet.XlsWorksheet.spr  (Unknown Source)
   at com.spire.xls.core.spreadsheet.XlsWorksheet.saveToImage(Unknown Source)


Anyway at the moment I only need the free edition, and just the functionality to convert the first sheet to an image.

gabiaxel
 
Posts: 4
Joined: Sat Jul 04, 2020 5:18 pm

Tue Jul 07, 2020 6:04 am

Hi Gabriel,

Thanks for your more information.
I tested the following code with the free Spire.Office on MacOS and indeed found the application threw the error "NullPointerException". However, I found that the application can exit normally and the output file can be generated successfully. Anyway, I will pass this issue to our Dev team for further investigation. If there is any update, we will let you know.
Code: Select all
        Workbook wb = new Workbook();
        Worksheet sheet = wb.getWorksheets().get(0);
        sheet.getRange().get(1,1).setValue("test");
        sheet.saveToImage("out.png");

Besides, regarding "I get an exception on Worksheet.saveToImage() for several spreadsheets I tried" you mentioned, could you please provide some sample files for our further investigation? You could send them to us(support@e-iceblue.com) via email. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Tue Jul 07, 2020 7:00 am

I tried the code you attached and it also produces the same exception in Worksheet.saveToImage(). I tried both e-iceblue:spire.office:3.6.4 and e-iceblue:spire.xls:3.6.7 with the same result.

While at it, I would like to request overloading Worksheet.saveToImage(OutputStream), because in production I don't need the file in the local filesystem where the code runs, but I save it to a cloud storage and/or send it in the HTTP response.

Thanks.

gabiaxel
 
Posts: 4
Joined: Sat Jul 04, 2020 5:18 pm

Tue Jul 07, 2020 12:06 pm

Hello,

Thanks for your feedback.
I tested the code with both spire.office 3.6.4 and spire.xls 3.6.7 and did get the exception when invoking the Worksheet.saveToImage() method. I will pass this issue to our Dev team for further investigation. If there is any update, we will inform you.
As for saving the worksheet to the image stream, you could refer to the following code snippet.
Code: Select all
        BufferedImage bufferedImage = sheet.toImage(sheet.getFirstRow(), sheet.getFirstColumn(), sheet.getLastRow(), sheet.getLastColumn());
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            ImageIO.write(bufferedImage, "png", os);
        } catch (IOException e) {
            e.printStackTrace();
        }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Aug 13, 2020 10:28 am

Hello Gabriel,

Thanks for your patient waiting.
Glad to inform you that we just released Spire.Office for Java Version:3.8.2 which resolves the issue that the application threw "NullPointerException" when converting Excel to image. Welcome to download it and test you case.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Sep 30, 2020 9:27 am

Hello Gabriel,

Hope you are doing well.
Glad to inform you that we just released Free Spire.Office for Java Version:3.9.0, it fixes the issue that the application threw the error "NullPointerException" when converting to image. Welcome to download it and test.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Sep 30, 2020 1:47 pm

Works fine now, thanks.

gabiaxel
 
Posts: 4
Joined: Sat Jul 04, 2020 5:18 pm

Thu Oct 01, 2020 1:34 am

Hi,

Thanks for your feedback.
Any question, please feel free to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.XLS