ImageIO.read returns NULL, with no errors
The following code seems not to work, even though the file appears to be found just fine.
images = new BufferedImage[32];
FileInputStream fis = null;
for (int i = 0; i < 32; i++) {
File file = new File("tiles\"+i+".bmp");
if (!file.exists()){
System.out.println("File "+i+" failed");
}
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.err.println(e + "" + i);
}
try {
images[i] = ImageIO.read(fis);
} catch (IOException e) {
System.err.println(e + "" + i);
}
if (images[i] == null) {
System.out.println("Image "+i+" failed");
}
}
Thanks in advance for any help.
Edit: The result is me attempting to Graphics.drawImage(images[0]);, and it giving me a null pointer exception. This code here completes fine.
Edit: Changed moved the if(!file.exists()) as suggested, and wrapped the file in an input stream.
java image
add a comment |
The following code seems not to work, even though the file appears to be found just fine.
images = new BufferedImage[32];
FileInputStream fis = null;
for (int i = 0; i < 32; i++) {
File file = new File("tiles\"+i+".bmp");
if (!file.exists()){
System.out.println("File "+i+" failed");
}
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.err.println(e + "" + i);
}
try {
images[i] = ImageIO.read(fis);
} catch (IOException e) {
System.err.println(e + "" + i);
}
if (images[i] == null) {
System.out.println("Image "+i+" failed");
}
}
Thanks in advance for any help.
Edit: The result is me attempting to Graphics.drawImage(images[0]);, and it giving me a null pointer exception. This code here completes fine.
Edit: Changed moved the if(!file.exists()) as suggested, and wrapped the file in an input stream.
java image
3
RTFM
– mre
Mar 30 '12 at 13:34
Could you describe the result? A wild guess: the path in incorrect...
– Alexis Dufrenoy
Mar 30 '12 at 13:36
Why don'y you put your test if (!file.exists()) System.out.println("File "+i+" failed"); before the read?
– Alexis Dufrenoy
Mar 30 '12 at 13:38
add a comment |
The following code seems not to work, even though the file appears to be found just fine.
images = new BufferedImage[32];
FileInputStream fis = null;
for (int i = 0; i < 32; i++) {
File file = new File("tiles\"+i+".bmp");
if (!file.exists()){
System.out.println("File "+i+" failed");
}
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.err.println(e + "" + i);
}
try {
images[i] = ImageIO.read(fis);
} catch (IOException e) {
System.err.println(e + "" + i);
}
if (images[i] == null) {
System.out.println("Image "+i+" failed");
}
}
Thanks in advance for any help.
Edit: The result is me attempting to Graphics.drawImage(images[0]);, and it giving me a null pointer exception. This code here completes fine.
Edit: Changed moved the if(!file.exists()) as suggested, and wrapped the file in an input stream.
java image
The following code seems not to work, even though the file appears to be found just fine.
images = new BufferedImage[32];
FileInputStream fis = null;
for (int i = 0; i < 32; i++) {
File file = new File("tiles\"+i+".bmp");
if (!file.exists()){
System.out.println("File "+i+" failed");
}
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
System.err.println(e + "" + i);
}
try {
images[i] = ImageIO.read(fis);
} catch (IOException e) {
System.err.println(e + "" + i);
}
if (images[i] == null) {
System.out.println("Image "+i+" failed");
}
}
Thanks in advance for any help.
Edit: The result is me attempting to Graphics.drawImage(images[0]);, and it giving me a null pointer exception. This code here completes fine.
Edit: Changed moved the if(!file.exists()) as suggested, and wrapped the file in an input stream.
java image
java image
edited Apr 23 '13 at 10:41


d.raev
5,60163866
5,60163866
asked Mar 30 '12 at 13:29
Naberius
100117
100117
3
RTFM
– mre
Mar 30 '12 at 13:34
Could you describe the result? A wild guess: the path in incorrect...
– Alexis Dufrenoy
Mar 30 '12 at 13:36
Why don'y you put your test if (!file.exists()) System.out.println("File "+i+" failed"); before the read?
– Alexis Dufrenoy
Mar 30 '12 at 13:38
add a comment |
3
RTFM
– mre
Mar 30 '12 at 13:34
Could you describe the result? A wild guess: the path in incorrect...
– Alexis Dufrenoy
Mar 30 '12 at 13:36
Why don'y you put your test if (!file.exists()) System.out.println("File "+i+" failed"); before the read?
– Alexis Dufrenoy
Mar 30 '12 at 13:38
3
3
RTFM
– mre
Mar 30 '12 at 13:34
RTFM
– mre
Mar 30 '12 at 13:34
Could you describe the result? A wild guess: the path in incorrect...
– Alexis Dufrenoy
Mar 30 '12 at 13:36
Could you describe the result? A wild guess: the path in incorrect...
– Alexis Dufrenoy
Mar 30 '12 at 13:36
Why don'y you put your test if (!file.exists()) System.out.println("File "+i+" failed"); before the read?
– Alexis Dufrenoy
Mar 30 '12 at 13:38
Why don'y you put your test if (!file.exists()) System.out.println("File "+i+" failed"); before the read?
– Alexis Dufrenoy
Mar 30 '12 at 13:38
add a comment |
3 Answers
3
active
oldest
votes
ImageIO.read(file); will return null if no registered ImageReader is not found. Please check whether you have registered any ImageReader or not.
I think this code snippet could help you
File file = new File("bear.jpg"); // I have bear.jpg in my working directory
FileInputStream fis = new FileInputStream(file);
BufferedImage image = ImageIO.read(fis); //reading the image file
You just need to wrap the file into an FileInputStream and then pass it to read()
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
|
show 1 more comment
ImageIO.read(*...)
will only load these image types GIF, PNG, JPEG, BMP, and WBMP.
Any other image type will return null
without error.
reference:
http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
I do realize this is not a solution to the specific original problem but it is a solution to the question asked.
add a comment |
Try wrap you InputStream into BufferedInputStream:
fis = new FileInputStream(file); ==>
new BufferedInputStream(new FileInputStream(file));
add a 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%2f9943962%2fimageio-read-returns-null-with-no-errors%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
ImageIO.read(file); will return null if no registered ImageReader is not found. Please check whether you have registered any ImageReader or not.
I think this code snippet could help you
File file = new File("bear.jpg"); // I have bear.jpg in my working directory
FileInputStream fis = new FileInputStream(file);
BufferedImage image = ImageIO.read(fis); //reading the image file
You just need to wrap the file into an FileInputStream and then pass it to read()
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
|
show 1 more comment
ImageIO.read(file); will return null if no registered ImageReader is not found. Please check whether you have registered any ImageReader or not.
I think this code snippet could help you
File file = new File("bear.jpg"); // I have bear.jpg in my working directory
FileInputStream fis = new FileInputStream(file);
BufferedImage image = ImageIO.read(fis); //reading the image file
You just need to wrap the file into an FileInputStream and then pass it to read()
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
|
show 1 more comment
ImageIO.read(file); will return null if no registered ImageReader is not found. Please check whether you have registered any ImageReader or not.
I think this code snippet could help you
File file = new File("bear.jpg"); // I have bear.jpg in my working directory
FileInputStream fis = new FileInputStream(file);
BufferedImage image = ImageIO.read(fis); //reading the image file
You just need to wrap the file into an FileInputStream and then pass it to read()
ImageIO.read(file); will return null if no registered ImageReader is not found. Please check whether you have registered any ImageReader or not.
I think this code snippet could help you
File file = new File("bear.jpg"); // I have bear.jpg in my working directory
FileInputStream fis = new FileInputStream(file);
BufferedImage image = ImageIO.read(fis); //reading the image file
You just need to wrap the file into an FileInputStream and then pass it to read()
answered Mar 30 '12 at 13:34


Chandra Sekhar
12k125692
12k125692
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
|
show 1 more comment
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
I'm probably still not doing this properly, but what I did do was unsuccessful. I changed the code above to show what was changed.
– Naberius
Mar 30 '12 at 13:59
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
Can you say what are your image file names in the disk?
– Chandra Sekhar
Mar 30 '12 at 14:07
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
@Naberius Can you say what are your image file names in the disk? It is perfectly working in my case.
– Chandra Sekhar
Mar 30 '12 at 14:16
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
Sorry, no weekend internet access. The files are named 0.bmp, 1.bmp, up to 31. They're also stored in a folder called "tiles", but nothing changes by taking them out of said folder.
– Naberius
Apr 2 '12 at 13:12
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
@Naberius Then try using File file = new File("tiles"+i+".bmp"); this.
– Chandra Sekhar
Apr 2 '12 at 13:20
|
show 1 more comment
ImageIO.read(*...)
will only load these image types GIF, PNG, JPEG, BMP, and WBMP.
Any other image type will return null
without error.
reference:
http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
I do realize this is not a solution to the specific original problem but it is a solution to the question asked.
add a comment |
ImageIO.read(*...)
will only load these image types GIF, PNG, JPEG, BMP, and WBMP.
Any other image type will return null
without error.
reference:
http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
I do realize this is not a solution to the specific original problem but it is a solution to the question asked.
add a comment |
ImageIO.read(*...)
will only load these image types GIF, PNG, JPEG, BMP, and WBMP.
Any other image type will return null
without error.
reference:
http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
I do realize this is not a solution to the specific original problem but it is a solution to the question asked.
ImageIO.read(*...)
will only load these image types GIF, PNG, JPEG, BMP, and WBMP.
Any other image type will return null
without error.
reference:
http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
I do realize this is not a solution to the specific original problem but it is a solution to the question asked.
answered Mar 31 '13 at 4:18
Irrationalkilla
41345
41345
add a comment |
add a comment |
Try wrap you InputStream into BufferedInputStream:
fis = new FileInputStream(file); ==>
new BufferedInputStream(new FileInputStream(file));
add a comment |
Try wrap you InputStream into BufferedInputStream:
fis = new FileInputStream(file); ==>
new BufferedInputStream(new FileInputStream(file));
add a comment |
Try wrap you InputStream into BufferedInputStream:
fis = new FileInputStream(file); ==>
new BufferedInputStream(new FileInputStream(file));
Try wrap you InputStream into BufferedInputStream:
fis = new FileInputStream(file); ==>
new BufferedInputStream(new FileInputStream(file));
answered Oct 14 '14 at 13:40


Ahmed MANSOUR
1,18111425
1,18111425
add a comment |
add a 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f9943962%2fimageio-read-returns-null-with-no-errors%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
3
RTFM
– mre
Mar 30 '12 at 13:34
Could you describe the result? A wild guess: the path in incorrect...
– Alexis Dufrenoy
Mar 30 '12 at 13:36
Why don'y you put your test if (!file.exists()) System.out.println("File "+i+" failed"); before the read?
– Alexis Dufrenoy
Mar 30 '12 at 13:38