Free Support Forum - aspose.com

Java- cell- deflateBytes error when add image to cell

Hi,

Do you know what may cause this error when we try to generate an excel file with image?

Much Thanks,
Hong

ERROR 2011-06-18 08:19:04,923 [com.caci.arms.report.QuicklookAdHocReport] - deflateBytes
java.lang.NullPointerException: deflateBytes
at java.util.zip.Deflater.deflate([BII)I(Unknown Source)
at com.sun.imageio.plugins.png.IDATOutputStream.deflate(PNGImageWriter.java:197)
at com.sun.imageio.plugins.png.IDATOutputStream.write(PNGImageWriter.java:191)
at com.sun.imageio.plugins.png.IDATOutputStream.write(PNGImageWriter.java:219)
at com.sun.imageio.plugins.png.PNGImageWriter.encodePass(PNGImageWriter.java:856)
at com.sun.imageio.plugins.png.PNGImageWriter.write_IDAT(PNGImageWriter.java:881)
at com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1106)
at javax.imageio.ImageWriter.write(ImageWriter.java:598)
at javax.imageio.ImageIO.write(ImageIO.java:1429)
at javax.imageio.ImageIO.write(ImageIO.java:1524)
at com.aspose.cells.bF.a([ILjava.io.InputStream;)[B(Unknown Source)
at com.aspose.cells.fn.a(ILjava.io.InputStream;)Lcom.aspose.cells.dS;(Unknown Source)
at com.aspose.cells.he.a(Ljava.io.InputStream;)Lcom.aspose.cells.dS;(Unknown Source)
at com.aspose.cells.Shape.b(Ljava.io.InputStream;)Lcom.aspose.cells.dS;(Unknown Source)
at com.aspose.cells.Picture.(Lcom.aspose.cells.Shapes;Lcom.aspose.cells.CellArea;Ljava.io.InputStream;)V(Unknown Source)
at com.aspose.cells.Shapes.addPicture(IIIILjava.io.InputStream;)Lcom.aspose.cells.Picture;(Unknown Source)
at com.caci.arms.utility.aspose.AsposeExcelUtility.setUtilsCells(AsposeExcelUtility.java:4210)
at com.caci.arms.utility.aspose.AsposeExcelUtility.setUtilsCells(AsposeExcelUtility.java:4170)
at com.caci.arms.utility.aspose.AsposeExcelUtility.setUtilsCells(AsposeExcelUtility.java:4116)
at com.caci.arms.utility.aspose.AsposeExcelUtility.setUtilsCells(AsposeExcelUtility.java:4090)
at com.caci.arms.report.QuicklookAdHocReport.buildAsposeQuicklook(QuicklookAdHocReport.java:1823)
at com.caci.arms.report.QuicklookAdHocReport.processQuicklook(QuicklookAdHocReport.java:1005)
at com.caci.arms.report.QuicklookAdHocReport.processRequest(QuicklookAdHocReport.java:205)
at com.caci.arms.report.QuicklookAdHocReport.doPost(QuicklookAdHocReport.java:457)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at com.caci.arms.cf.NewReleaseFilter.doFilter(NewReleaseFilter.java:95)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at com.caci.arms.utility.GarbageCollectionFilter.doFilter(GarbageCollectionFilter.java:43)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at com.caci.arms.cf.UserInfoFilter.doFilter(UserInfoFilter.java:170)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)


//this is our code
protected void setUtilsCells(int sheetIndex,
int rowStartIndex,
int rowSpan,
int colStartIndex,
int colSpan,
File cellValue,
Style cellStyle,
StyleFlag cellStyleFlags)
throws java.lang.IllegalArgumentException,IOException{

if((cellValue != null) && cellValue.exists() && cellValue.isFile()){

// throw exception if rowSpan or colSpan is negative
if(rowSpan < 0 || colSpan < 0){ throw new IllegalArgumentException(“both rowSpan & colSpan must be non-negative”); }

InputStream iStream = null;
try{
// obtain an input Stream of interest
iStream = new FileInputStream(cellValue);
// obtain a reference to the worksheet of interest
Worksheet sheet = getUtilsSheet(sheetIndex);
// apply value
//AsposeExcelUtility.java:4210 where the error started.
Picture picture = sheet.getShapes().addPicture(rowStartIndex,
colStartIndex,
rowStartIndex,
colStartIndex,
iStream);


//set the picture height and width 1 pixel smaller for sorting with images work correctly
int height = picture.getHeight();
int width = picture.getWidth();
picture.setHeight(height - 1);
picture.setWidth(width - 1);

}
catch(FileNotFoundException fnfe){
// should not be possible
throw new IllegalArgumentException(“file not found, should not be possible”);
}
finally{
if(iStream != null){
iStream.close();
iStream = null;
}
}

// obtain a reference to the cell of interest
Cell cell = getUtilsCell(sheetIndex, rowStartIndex, colStartIndex);

// apply style
if(cellStyleFlags == null){cell.setStyle(cellStyle);}
else{cell.applyStyle(cellStyle,cellStyleFlags);}
}
return;
}

Hi,

Kindly create a sample console application and post/paste the complete sample code here with template files to show the issue, we will check your issue soon.

Also, which version of the product you are using?

Thank you.

I’m using Aspose.Cells for Java v2.5.0.

I’m using Aspose Cell java for a web application so it’s hard to create a sample console application.
I’d like to have some hint what to look for when you see error like that.

Thanks,
Hong

Hi,

We think the issue might be related to Java’s ImageIO. We need your image file, from your code, we think it is the file represented by the variable “cellValue” etc.

Thank you.