java.util.NoSuchElementException while writing image on Excel file using Apache poi 3.8 in javaHow do I create a file and write to it in Java?Apache POI Excel - how to configure columns to be expanded?Writing Excel file from Java with apache poiWriting a List instance to Excel file - Apache POIWhat is the better API to Reading Excel sheets in java - JXL or Apache POIWrite in Excel Apache POINullPointerException while writing to an excel file using Apache POIRepeatedly writing in same Excel file with Apache POIException with writing new excel file with Apache POIJava Apache Poi Write Excel

Is there an Impartial Brexit Deal comparison site?

Can I Retrieve Email Addresses from BCC?

Should my PhD thesis be submitted under my legal name?

Implement the Thanos sorting algorithm

Was Spock the First Vulcan in Starfleet?

What is the term when two people sing in harmony, but they aren't singing the same notes?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Why Were Madagascar and New Zealand Discovered So Late?

What would be the benefits of having both a state and local currencies?

Is it correct to write "is not focus on"?

Go Pregnant or Go Home

Is HostGator storing my password in plaintext?

Why "be dealt cards" rather than "be dealing cards"?

when is out of tune ok?

What defines a dissertation?

Displaying the order of the columns of a table

Hide Select Output from T-SQL

Ways to speed up user implemented RK4

Is it okay / does it make sense for another player to join a running game of Munchkin?

Products and sum of cubes in Fibonacci

How can I use the arrow sign in my bash prompt?

What will be the benefits of Brexit?

Opposite of a diet

What is the oldest known work of fiction?



java.util.NoSuchElementException while writing image on Excel file using Apache poi 3.8 in java


How do I create a file and write to it in Java?Apache POI Excel - how to configure columns to be expanded?Writing Excel file from Java with apache poiWriting a List instance to Excel file - Apache POIWhat is the better API to Reading Excel sheets in java - JXL or Apache POIWrite in Excel Apache POINullPointerException while writing to an excel file using Apache POIRepeatedly writing in same Excel file with Apache POIException with writing new excel file with Apache POIJava Apache Poi Write Excel













1















I am getting below inconsistent exception when i call resize method.
It fails 10% of time, because of below error. I can't reproduced it on my local environment.



java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:836)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:528)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at org.apache.poi.ss.util.ImageUtils.getImageDimension(ImageUtils.java:64)
at org.apache.poi.xssf.usermodel.XSSFPicture.getImageDimension(XSSFPicture.java:278)
at org.apache.poi.xssf.usermodel.XSSFPicture.getPreferredSize(XSSFPicture.java:203)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:170)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:152)


Please suggest any root cause.



The code snippet which i have written as follows



Sheet sheet2 = workbook.createSheet("Graph");
//feedChartToExcel = new FileInputStream("C:\Users\idnyob\Desktop\PcrChartImageFogX7eRH4c1551955300676.png");
feedChartToExcel = new FileInputStream(this.imagePath);

// Convert picture to be added into a byte array
byte[] bytes = IOUtils.toByteArray(feedChartToExcel);


// Add Picture to Workbook, Specify picture type as PNG and Get an Index
int pictureId = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
// Close the InputStream. We are ready to attach the image to workbook now
feedChartToExcel.close();
// Create the drawing container
XSSFDrawing drawing = (XSSFDrawing) sheet2.createDrawingPatriarch();
// Create an anchor point
XSSFClientAnchor anchor = new XSSFClientAnchor();
// Define top left corner, and we can resize picture suitable from there
anchor.setCol1(2);
anchor.setRow1(1);
// Invoke createPicture and pass the anchor point and ID
XSSFPicture picture = drawing.createPicture(anchor, pictureId);
// Call resize method, which resizes the image
picture.resize();









share|improve this question

















  • 1





    Why are you using a version of Apache POI that is 7+ years old with loads of known bugs? What happens when you upgrade to a more modern and supported version?

    – Gagravarr
    Mar 8 at 10:08











  • Could you confirm this exception is related to this version 3.8

    – Yogesh Bombe
    Mar 8 at 10:12











  • According to that exception org.apache.poi.ss.util.ImageUtils.getImageDimension calls javax.imageio.ImageIO$ImageReaderIterator.next without checking whether there is a next element (would be simple Iterator.hasNext). And after looking in the code I found that this is true even in last apache poi 4.0.1. But this is a violation of such basic programming rules that apache poi should improving that asap.

    – Axel Richter
    Mar 8 at 13:59















1















I am getting below inconsistent exception when i call resize method.
It fails 10% of time, because of below error. I can't reproduced it on my local environment.



java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:836)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:528)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at org.apache.poi.ss.util.ImageUtils.getImageDimension(ImageUtils.java:64)
at org.apache.poi.xssf.usermodel.XSSFPicture.getImageDimension(XSSFPicture.java:278)
at org.apache.poi.xssf.usermodel.XSSFPicture.getPreferredSize(XSSFPicture.java:203)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:170)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:152)


Please suggest any root cause.



The code snippet which i have written as follows



Sheet sheet2 = workbook.createSheet("Graph");
//feedChartToExcel = new FileInputStream("C:\Users\idnyob\Desktop\PcrChartImageFogX7eRH4c1551955300676.png");
feedChartToExcel = new FileInputStream(this.imagePath);

// Convert picture to be added into a byte array
byte[] bytes = IOUtils.toByteArray(feedChartToExcel);


// Add Picture to Workbook, Specify picture type as PNG and Get an Index
int pictureId = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
// Close the InputStream. We are ready to attach the image to workbook now
feedChartToExcel.close();
// Create the drawing container
XSSFDrawing drawing = (XSSFDrawing) sheet2.createDrawingPatriarch();
// Create an anchor point
XSSFClientAnchor anchor = new XSSFClientAnchor();
// Define top left corner, and we can resize picture suitable from there
anchor.setCol1(2);
anchor.setRow1(1);
// Invoke createPicture and pass the anchor point and ID
XSSFPicture picture = drawing.createPicture(anchor, pictureId);
// Call resize method, which resizes the image
picture.resize();









share|improve this question

















  • 1





    Why are you using a version of Apache POI that is 7+ years old with loads of known bugs? What happens when you upgrade to a more modern and supported version?

    – Gagravarr
    Mar 8 at 10:08











  • Could you confirm this exception is related to this version 3.8

    – Yogesh Bombe
    Mar 8 at 10:12











  • According to that exception org.apache.poi.ss.util.ImageUtils.getImageDimension calls javax.imageio.ImageIO$ImageReaderIterator.next without checking whether there is a next element (would be simple Iterator.hasNext). And after looking in the code I found that this is true even in last apache poi 4.0.1. But this is a violation of such basic programming rules that apache poi should improving that asap.

    – Axel Richter
    Mar 8 at 13:59













1












1








1


1






I am getting below inconsistent exception when i call resize method.
It fails 10% of time, because of below error. I can't reproduced it on my local environment.



java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:836)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:528)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at org.apache.poi.ss.util.ImageUtils.getImageDimension(ImageUtils.java:64)
at org.apache.poi.xssf.usermodel.XSSFPicture.getImageDimension(XSSFPicture.java:278)
at org.apache.poi.xssf.usermodel.XSSFPicture.getPreferredSize(XSSFPicture.java:203)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:170)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:152)


Please suggest any root cause.



The code snippet which i have written as follows



Sheet sheet2 = workbook.createSheet("Graph");
//feedChartToExcel = new FileInputStream("C:\Users\idnyob\Desktop\PcrChartImageFogX7eRH4c1551955300676.png");
feedChartToExcel = new FileInputStream(this.imagePath);

// Convert picture to be added into a byte array
byte[] bytes = IOUtils.toByteArray(feedChartToExcel);


// Add Picture to Workbook, Specify picture type as PNG and Get an Index
int pictureId = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
// Close the InputStream. We are ready to attach the image to workbook now
feedChartToExcel.close();
// Create the drawing container
XSSFDrawing drawing = (XSSFDrawing) sheet2.createDrawingPatriarch();
// Create an anchor point
XSSFClientAnchor anchor = new XSSFClientAnchor();
// Define top left corner, and we can resize picture suitable from there
anchor.setCol1(2);
anchor.setRow1(1);
// Invoke createPicture and pass the anchor point and ID
XSSFPicture picture = drawing.createPicture(anchor, pictureId);
// Call resize method, which resizes the image
picture.resize();









share|improve this question














I am getting below inconsistent exception when i call resize method.
It fails 10% of time, because of below error. I can't reproduced it on my local environment.



java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:836)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:528)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at org.apache.poi.ss.util.ImageUtils.getImageDimension(ImageUtils.java:64)
at org.apache.poi.xssf.usermodel.XSSFPicture.getImageDimension(XSSFPicture.java:278)
at org.apache.poi.xssf.usermodel.XSSFPicture.getPreferredSize(XSSFPicture.java:203)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:170)
at org.apache.poi.xssf.usermodel.XSSFPicture.resize(XSSFPicture.java:152)


Please suggest any root cause.



The code snippet which i have written as follows



Sheet sheet2 = workbook.createSheet("Graph");
//feedChartToExcel = new FileInputStream("C:\Users\idnyob\Desktop\PcrChartImageFogX7eRH4c1551955300676.png");
feedChartToExcel = new FileInputStream(this.imagePath);

// Convert picture to be added into a byte array
byte[] bytes = IOUtils.toByteArray(feedChartToExcel);


// Add Picture to Workbook, Specify picture type as PNG and Get an Index
int pictureId = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
// Close the InputStream. We are ready to attach the image to workbook now
feedChartToExcel.close();
// Create the drawing container
XSSFDrawing drawing = (XSSFDrawing) sheet2.createDrawingPatriarch();
// Create an anchor point
XSSFClientAnchor anchor = new XSSFClientAnchor();
// Define top left corner, and we can resize picture suitable from there
anchor.setCol1(2);
anchor.setRow1(1);
// Invoke createPicture and pass the anchor point and ID
XSSFPicture picture = drawing.createPicture(anchor, pictureId);
// Call resize method, which resizes the image
picture.resize();






java apache-poi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 9:46









Yogesh BombeYogesh Bombe

10418




10418







  • 1





    Why are you using a version of Apache POI that is 7+ years old with loads of known bugs? What happens when you upgrade to a more modern and supported version?

    – Gagravarr
    Mar 8 at 10:08











  • Could you confirm this exception is related to this version 3.8

    – Yogesh Bombe
    Mar 8 at 10:12











  • According to that exception org.apache.poi.ss.util.ImageUtils.getImageDimension calls javax.imageio.ImageIO$ImageReaderIterator.next without checking whether there is a next element (would be simple Iterator.hasNext). And after looking in the code I found that this is true even in last apache poi 4.0.1. But this is a violation of such basic programming rules that apache poi should improving that asap.

    – Axel Richter
    Mar 8 at 13:59












  • 1





    Why are you using a version of Apache POI that is 7+ years old with loads of known bugs? What happens when you upgrade to a more modern and supported version?

    – Gagravarr
    Mar 8 at 10:08











  • Could you confirm this exception is related to this version 3.8

    – Yogesh Bombe
    Mar 8 at 10:12











  • According to that exception org.apache.poi.ss.util.ImageUtils.getImageDimension calls javax.imageio.ImageIO$ImageReaderIterator.next without checking whether there is a next element (would be simple Iterator.hasNext). And after looking in the code I found that this is true even in last apache poi 4.0.1. But this is a violation of such basic programming rules that apache poi should improving that asap.

    – Axel Richter
    Mar 8 at 13:59







1




1





Why are you using a version of Apache POI that is 7+ years old with loads of known bugs? What happens when you upgrade to a more modern and supported version?

– Gagravarr
Mar 8 at 10:08





Why are you using a version of Apache POI that is 7+ years old with loads of known bugs? What happens when you upgrade to a more modern and supported version?

– Gagravarr
Mar 8 at 10:08













Could you confirm this exception is related to this version 3.8

– Yogesh Bombe
Mar 8 at 10:12





Could you confirm this exception is related to this version 3.8

– Yogesh Bombe
Mar 8 at 10:12













According to that exception org.apache.poi.ss.util.ImageUtils.getImageDimension calls javax.imageio.ImageIO$ImageReaderIterator.next without checking whether there is a next element (would be simple Iterator.hasNext). And after looking in the code I found that this is true even in last apache poi 4.0.1. But this is a violation of such basic programming rules that apache poi should improving that asap.

– Axel Richter
Mar 8 at 13:59





According to that exception org.apache.poi.ss.util.ImageUtils.getImageDimension calls javax.imageio.ImageIO$ImageReaderIterator.next without checking whether there is a next element (would be simple Iterator.hasNext). And after looking in the code I found that this is true even in last apache poi 4.0.1. But this is a violation of such basic programming rules that apache poi should improving that asap.

– Axel Richter
Mar 8 at 13:59












1 Answer
1






active

oldest

votes


















0














Because the question was about the root cause of that exception, here is the answer:



org.apache.poi.ss.util.ImageUtils.getImageDimension does the following:



If the given type is either Workbook.PICTURE_TYPE_JPEG or Workbook.PICTURE_TYPE_PNG or Workbook.PICTURE_TYPE_DIB, then it uses javax.imageio.ImageIO for creating a ImageInputStream from the given InputStream. Then it gets a Iterator of possible ImageReaders for that ImageInputStream. And then it does the wrong. It calls Iterator.next to get the first possible ImageReader without checking whether the Iterator has a next element at all. That trows java.util.NoSuchElementException if there is not a next element in Iterator.



But why there is not a next element in Iterator? Since there is only one call Iterator.next at all, there is not even one ImageReader in the Iterator. The Iterator has not even one element. But that means, that javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream. And that means that either the given InputStream was not an InputStream from jpeg, png or bmp picture or there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly.



Since it fails only inconsistent in other environments and never fails in OP's local environment, the first option is inapplicable. So my suspicion is that, if it fails, there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly. So what I would do is:



First: Determining using what picture type it fails (jpeg, png or bmp).



Second: Determining in what environment it fails (operating system, Java version, used frameworks, ...).



The apache poi version is not relevant since even apache poi 4.0.1 does the same wrong call to Iterator.next without checking Iterator.hasNext first: org.apache.poi.ss.util.ImageUtils.getImageDimension.






share|improve this answer

























  • Image type is always same .png and os is windows, java version is 8.

    – Yogesh Bombe
    Mar 12 at 5:30











  • Could you tell me what things i have to change.

    – Yogesh Bombe
    Mar 12 at 5:31











  • You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

    – Axel Richter
    Mar 12 at 6:09












  • It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

    – Yogesh Bombe
    Mar 12 at 6:49











  • Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

    – Axel Richter
    Mar 12 at 7:28










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060533%2fjava-util-nosuchelementexception-while-writing-image-on-excel-file-using-apache%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Because the question was about the root cause of that exception, here is the answer:



org.apache.poi.ss.util.ImageUtils.getImageDimension does the following:



If the given type is either Workbook.PICTURE_TYPE_JPEG or Workbook.PICTURE_TYPE_PNG or Workbook.PICTURE_TYPE_DIB, then it uses javax.imageio.ImageIO for creating a ImageInputStream from the given InputStream. Then it gets a Iterator of possible ImageReaders for that ImageInputStream. And then it does the wrong. It calls Iterator.next to get the first possible ImageReader without checking whether the Iterator has a next element at all. That trows java.util.NoSuchElementException if there is not a next element in Iterator.



But why there is not a next element in Iterator? Since there is only one call Iterator.next at all, there is not even one ImageReader in the Iterator. The Iterator has not even one element. But that means, that javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream. And that means that either the given InputStream was not an InputStream from jpeg, png or bmp picture or there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly.



Since it fails only inconsistent in other environments and never fails in OP's local environment, the first option is inapplicable. So my suspicion is that, if it fails, there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly. So what I would do is:



First: Determining using what picture type it fails (jpeg, png or bmp).



Second: Determining in what environment it fails (operating system, Java version, used frameworks, ...).



The apache poi version is not relevant since even apache poi 4.0.1 does the same wrong call to Iterator.next without checking Iterator.hasNext first: org.apache.poi.ss.util.ImageUtils.getImageDimension.






share|improve this answer

























  • Image type is always same .png and os is windows, java version is 8.

    – Yogesh Bombe
    Mar 12 at 5:30











  • Could you tell me what things i have to change.

    – Yogesh Bombe
    Mar 12 at 5:31











  • You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

    – Axel Richter
    Mar 12 at 6:09












  • It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

    – Yogesh Bombe
    Mar 12 at 6:49











  • Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

    – Axel Richter
    Mar 12 at 7:28















0














Because the question was about the root cause of that exception, here is the answer:



org.apache.poi.ss.util.ImageUtils.getImageDimension does the following:



If the given type is either Workbook.PICTURE_TYPE_JPEG or Workbook.PICTURE_TYPE_PNG or Workbook.PICTURE_TYPE_DIB, then it uses javax.imageio.ImageIO for creating a ImageInputStream from the given InputStream. Then it gets a Iterator of possible ImageReaders for that ImageInputStream. And then it does the wrong. It calls Iterator.next to get the first possible ImageReader without checking whether the Iterator has a next element at all. That trows java.util.NoSuchElementException if there is not a next element in Iterator.



But why there is not a next element in Iterator? Since there is only one call Iterator.next at all, there is not even one ImageReader in the Iterator. The Iterator has not even one element. But that means, that javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream. And that means that either the given InputStream was not an InputStream from jpeg, png or bmp picture or there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly.



Since it fails only inconsistent in other environments and never fails in OP's local environment, the first option is inapplicable. So my suspicion is that, if it fails, there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly. So what I would do is:



First: Determining using what picture type it fails (jpeg, png or bmp).



Second: Determining in what environment it fails (operating system, Java version, used frameworks, ...).



The apache poi version is not relevant since even apache poi 4.0.1 does the same wrong call to Iterator.next without checking Iterator.hasNext first: org.apache.poi.ss.util.ImageUtils.getImageDimension.






share|improve this answer

























  • Image type is always same .png and os is windows, java version is 8.

    – Yogesh Bombe
    Mar 12 at 5:30











  • Could you tell me what things i have to change.

    – Yogesh Bombe
    Mar 12 at 5:31











  • You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

    – Axel Richter
    Mar 12 at 6:09












  • It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

    – Yogesh Bombe
    Mar 12 at 6:49











  • Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

    – Axel Richter
    Mar 12 at 7:28













0












0








0







Because the question was about the root cause of that exception, here is the answer:



org.apache.poi.ss.util.ImageUtils.getImageDimension does the following:



If the given type is either Workbook.PICTURE_TYPE_JPEG or Workbook.PICTURE_TYPE_PNG or Workbook.PICTURE_TYPE_DIB, then it uses javax.imageio.ImageIO for creating a ImageInputStream from the given InputStream. Then it gets a Iterator of possible ImageReaders for that ImageInputStream. And then it does the wrong. It calls Iterator.next to get the first possible ImageReader without checking whether the Iterator has a next element at all. That trows java.util.NoSuchElementException if there is not a next element in Iterator.



But why there is not a next element in Iterator? Since there is only one call Iterator.next at all, there is not even one ImageReader in the Iterator. The Iterator has not even one element. But that means, that javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream. And that means that either the given InputStream was not an InputStream from jpeg, png or bmp picture or there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly.



Since it fails only inconsistent in other environments and never fails in OP's local environment, the first option is inapplicable. So my suspicion is that, if it fails, there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly. So what I would do is:



First: Determining using what picture type it fails (jpeg, png or bmp).



Second: Determining in what environment it fails (operating system, Java version, used frameworks, ...).



The apache poi version is not relevant since even apache poi 4.0.1 does the same wrong call to Iterator.next without checking Iterator.hasNext first: org.apache.poi.ss.util.ImageUtils.getImageDimension.






share|improve this answer















Because the question was about the root cause of that exception, here is the answer:



org.apache.poi.ss.util.ImageUtils.getImageDimension does the following:



If the given type is either Workbook.PICTURE_TYPE_JPEG or Workbook.PICTURE_TYPE_PNG or Workbook.PICTURE_TYPE_DIB, then it uses javax.imageio.ImageIO for creating a ImageInputStream from the given InputStream. Then it gets a Iterator of possible ImageReaders for that ImageInputStream. And then it does the wrong. It calls Iterator.next to get the first possible ImageReader without checking whether the Iterator has a next element at all. That trows java.util.NoSuchElementException if there is not a next element in Iterator.



But why there is not a next element in Iterator? Since there is only one call Iterator.next at all, there is not even one ImageReader in the Iterator. The Iterator has not even one element. But that means, that javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream. And that means that either the given InputStream was not an InputStream from jpeg, png or bmp picture or there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly.



Since it fails only inconsistent in other environments and never fails in OP's local environment, the first option is inapplicable. So my suspicion is that, if it fails, there is no currently registered ImageReader that claim to be able to decode jpeg, png or bmp pictures properly. So what I would do is:



First: Determining using what picture type it fails (jpeg, png or bmp).



Second: Determining in what environment it fails (operating system, Java version, used frameworks, ...).



The apache poi version is not relevant since even apache poi 4.0.1 does the same wrong call to Iterator.next without checking Iterator.hasNext first: org.apache.poi.ss.util.ImageUtils.getImageDimension.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 11:32

























answered Mar 9 at 11:10









Axel RichterAxel Richter

26.4k32039




26.4k32039












  • Image type is always same .png and os is windows, java version is 8.

    – Yogesh Bombe
    Mar 12 at 5:30











  • Could you tell me what things i have to change.

    – Yogesh Bombe
    Mar 12 at 5:31











  • You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

    – Axel Richter
    Mar 12 at 6:09












  • It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

    – Yogesh Bombe
    Mar 12 at 6:49











  • Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

    – Axel Richter
    Mar 12 at 7:28

















  • Image type is always same .png and os is windows, java version is 8.

    – Yogesh Bombe
    Mar 12 at 5:30











  • Could you tell me what things i have to change.

    – Yogesh Bombe
    Mar 12 at 5:31











  • You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

    – Axel Richter
    Mar 12 at 6:09












  • It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

    – Yogesh Bombe
    Mar 12 at 6:49











  • Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

    – Axel Richter
    Mar 12 at 7:28
















Image type is always same .png and os is windows, java version is 8.

– Yogesh Bombe
Mar 12 at 5:30





Image type is always same .png and os is windows, java version is 8.

– Yogesh Bombe
Mar 12 at 5:30













Could you tell me what things i have to change.

– Yogesh Bombe
Mar 12 at 5:31





Could you tell me what things i have to change.

– Yogesh Bombe
Mar 12 at 5:31













You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

– Axel Richter
Mar 12 at 6:09






You cannot change anything because, as said, javax.imageio.ImageIO was not able finding a currently registered ImageReader that claim to be able to decode the supplied ImageInputStream, which, as you told now, streams from a png file. And when it really only fails in other environments and never in your local environment, then there must be differences between the environments where it fails and your local environment. Try determining those differences to be able asking a more concrete question.

– Axel Richter
Mar 12 at 6:09














It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

– Yogesh Bombe
Mar 12 at 6:49





It fails in os - WIndows Server 2008 R2 Enterprise (64 bit) - Service Pack 1 and java "1.8.0_40" with Failure result 10%.

– Yogesh Bombe
Mar 12 at 6:49













Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

– Axel Richter
Mar 12 at 7:28





Cannot test. But Java 8 Update 40 sounds very old. So a Java update would be worth a try in my opinion.

– Axel Richter
Mar 12 at 7:28



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55060533%2fjava-util-nosuchelementexception-while-writing-image-on-excel-file-using-apache%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived