Null Pointer exception while chart to image transformation

Hi,


I received null pointer exception while converting chart to image.

Exception:
Caused by: java.lang.NullPointerException
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.e(Unknown Source)
at com.aspose.cells.gk.f(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.Chart.toImage(Unknown Source)
at (ExcelOfficeManager.java:241)

Code:
Workbook workbook = new Workbook(sourcePath);

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
imgOptions.setOnePagePerSheet(true);

WorksheetCollection worksheetCollection = workbook.getWorksheets();
for (int i = 0; i < worksheetCollection.getCount() && i < previewCount; i++) {
List charts = getAllCharts(worksheetCollection.get(i));
for (Chart chart : charts) {
String imageFilePath = “D:\test” + new Random().nextInt(500) + “.jpeg”;
chart.toImage((imageFilePath), imgOptions);
}
}

I attached my sample xls file. Can you please let me know where i did any mistak

Hi,

Thanks for your posting and using Aspose.Cells for Java.

We were able to replicate this exception using the latest version: Aspose.Cells
for Java v7.5.3.2
with the following code and using your source file. We have logged this issue in our database. We will look into it and fix this issue. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40621.

Java


String sourcePath = “F:\Shak-Data-RW\Downloads\test.xls”;


Workbook workbook = new Workbook(sourcePath);


ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

imgOptions.setImageFormat(ImageFormat.getJpeg());

imgOptions.setOnePagePerSheet(true);


Worksheet worksheet = workbook.getWorksheets().get(0);

Chart chart = worksheet.getCharts().get(0);


chart.toImage(sourcePath + “.out.jpg”, imgOptions);

Exception:
Exception in thread "main" java.lang.NullPointerException
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.e(Unknown Source)
at com.aspose.cells.gk.f(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.gk.a(Unknown Source)
at com.aspose.cells.Chart.toImage(Unknown Source)
at ClsAsposeTest.f1(ClsAsposeTest.java:58)
at ClsAsposeTest.main(ClsAsposeTest.java:28)

Hi,


Please try our latest version/fix: Aspose.Cells for Java v7.5.3.5 (attached), we have fixed your issue now.

Let us know your feedback.

Thank you.

HI,


Thanks for the response. Null pointer exception is resoved but now using this version will produce another exception

Caused by: java.lang.NegativeArraySizeException
at com.aspose.cells.PivotTable.getHorizontalBreaks(Unknown Source)
at com.aspose.cells.nr.a(Unknown Source)
at com.aspose.cells.nr.b(Unknown Source)
at com.aspose.cells.nr.a(Unknown Source)
at com.aspose.cells.nr.a(Unknown Source)
at com.aspose.cells.bdi.a(Unknown Source)
at com.aspose.cells.SheetRender.(Unknown Source)


Samle file is attached with this post.

Hi Ashish,

Thanks for your posting and using Aspose.Cells for Java.

Could you provide us sample code replicating this exception with the latest version? We have tested your issue with the following sample codes and it did not throw any exception. We have also attached the output images for your reference.

Java


Workbook workbook = new Workbook(path);


Worksheet worksheet = workbook.getWorksheets().get(0);


ImageOrPrintOptions options = new ImageOrPrintOptions();

options.setOnePagePerSheet(true);

options.setImageFormat(ImageFormat.getPng());


SheetRender sr = new SheetRender(worksheet, options);

sr.toImage(0, new FileOutputStream(path + “.out.png”));


Java
Workbook workbook = new Workbook(sourcePath);

ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
imgOptions.setOnePagePerSheet(true);

Worksheet worksheet = workbook.getWorksheets().get(0);
Chart chart = worksheet.getCharts().get(0);

chart.toImage(sourcePath + ".out.jpg", imgOptions);

Hi,


Change this
imgOptions.setOnePagePerSheet(true);

to
imgOptions.setOnePagePerSheet(false);

and you will get the exception.

Hi Ashish,

Thanks for your posting and using Aspose.Cells.

Now, we are able to replicate this exception using the following code. We have logged this issue in our database. We will look into it and resolve it. Once, the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40633.

Java


Workbook workbook = new Workbook(path);


Worksheet worksheet = workbook.getWorksheets().get(0);


ImageOrPrintOptions options = new ImageOrPrintOptions();

options.setOnePagePerSheet(false);

options.setImageFormat(ImageFormat.getPng());


SheetRender sr = new SheetRender(worksheet, options);

sr.toImage(0, new FileOutputStream(path + “.out.png”));

Exception:
Exception in thread "main" java.lang.NegativeArraySizeException
at com.aspose.cells.PivotTable.getHorizontalBreaks(Unknown Source)
at com.aspose.cells.nr.a(Unknown Source)
at com.aspose.cells.nr.b(Unknown Source)
at com.aspose.cells.nr.a(Unknown Source)
at com.aspose.cells.nr.a(Unknown Source)
at com.aspose.cells.bdi.a(Unknown Source)
at com.aspose.cells.SheetRender.(Unknown Source)
at ClsAsposeTest.Sheet2Image(ClsAsposeTest.java:66)
at ClsAsposeTest.f1(ClsAsposeTest.java:49)
at ClsAsposeTest.main(ClsAsposeTest.java:28)

The issues you have found earlier (filed as CELLSJAVA-40621;CELLSJAVA-40633) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,


You may try our latest fix as well: Aspose.Cells for Java v7.6.0.2 and it fixes your issue.

Thank you.