java.util.NoSuchElementException while writing image on Excel file using Apache poi 3.8 in java The 2019 Stack Overflow Developer Survey Results Are InHow 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 a "Democratic" Oligarchy-Style System Possible?
How to answer pointed "are you quitting" questioning when I don't want them to suspect
How can I autofill dates in Excel excluding Sunday?
Did Section 31 appear in Star Trek: The Next Generation?
What is the meaning of the verb "bear" in this context?
Why did Acorn's A3000 have red function keys?
Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?
Is three citations per paragraph excessive for undergraduate research paper?
Identify boardgame from Big movie
Is an up-to-date browser secure on an out-of-date OS?
Return to UK after being refused entry years previously
Geography at the pixel level
Does the shape of a die affect the probability of a number being rolled?
Why didn't the Event Horizon Telescope team mention Sagittarius A*?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Delete all lines which don't have n characters before delimiter
Apparent duplicates between Haynes service instructions and MOT
Is there any way to tell whether the shot is going to hit you or not?
Is this app Icon Browser Safe/Legit?
When should I buy a clipper card after flying to OAK?
Origin of "cooter" meaning "vagina"
How to support a colleague who finds meetings extremely tiring?
Is "plugging out" electronic devices an American expression?
What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?
java.util.NoSuchElementException while writing image on Excel file using Apache poi 3.8 in java
The 2019 Stack Overflow Developer Survey Results Are InHow 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
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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
add a comment |
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
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 exceptionorg.apache.poi.ss.util.ImageUtils.getImageDimension
callsjavax.imageio.ImageIO$ImageReaderIterator.next
without checking whether there is a next element (would be simpleIterator.hasNext
). And after looking in the code I found that this is true even in lastapache poi 4.0.1
. But this is a violation of such basic programming rules thatapache poi
should improving that asap.
– Axel Richter
Mar 8 at 13:59
add a comment |
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
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
java apache-poi
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 exceptionorg.apache.poi.ss.util.ImageUtils.getImageDimension
callsjavax.imageio.ImageIO$ImageReaderIterator.next
without checking whether there is a next element (would be simpleIterator.hasNext
). And after looking in the code I found that this is true even in lastapache poi 4.0.1
. But this is a violation of such basic programming rules thatapache poi
should improving that asap.
– Axel Richter
Mar 8 at 13:59
add a comment |
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 exceptionorg.apache.poi.ss.util.ImageUtils.getImageDimension
callsjavax.imageio.ImageIO$ImageReaderIterator.next
without checking whether there is a next element (would be simpleIterator.hasNext
). And after looking in the code I found that this is true even in lastapache poi 4.0.1
. But this is a violation of such basic programming rules thatapache 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
add a comment |
1 Answer
1
active
oldest
votes
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 ImageReader
s 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.
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 registeredImageReader
that claim to be able to decode the suppliedImageInputStream
, which, as you told now, streams from apng
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
|
show 1 more comment
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 ImageReader
s 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.
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 registeredImageReader
that claim to be able to decode the suppliedImageInputStream
, which, as you told now, streams from apng
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
|
show 1 more comment
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 ImageReader
s 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.
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 registeredImageReader
that claim to be able to decode the suppliedImageInputStream
, which, as you told now, streams from apng
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
|
show 1 more comment
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 ImageReader
s 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.
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 ImageReader
s 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.
edited Mar 9 at 11:32
answered Mar 9 at 11:10
Axel RichterAxel Richter
26.6k32140
26.6k32140
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 registeredImageReader
that claim to be able to decode the suppliedImageInputStream
, which, as you told now, streams from apng
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
|
show 1 more comment
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 registeredImageReader
that claim to be able to decode the suppliedImageInputStream
, which, as you told now, streams from apng
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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
callsjavax.imageio.ImageIO$ImageReaderIterator.next
without checking whether there is a next element (would be simpleIterator.hasNext
). And after looking in the code I found that this is true even in lastapache poi 4.0.1
. But this is a violation of such basic programming rules thatapache poi
should improving that asap.– Axel Richter
Mar 8 at 13:59