Reputation: 35772
I'm trying to load this image using ImageIO.read() using the 1.7.0u JVM:
http://taste-for-adventure.tablespoon.com/files/2012/02/2012-02-05-poll-hotdog-275w.jpg
Chrome has no trouble with it, but Java throws the following exception:
java.lang.NullPointerException
at java.awt.color.ICC_Profile.intFromBigEndian(ICC_Profile.java:1770)
at java.awt.color.ICC_Profile.getNumComponents(ICC_Profile.java:1462)
at sun.java2d.cmm.lcms.LCMSTransform.<init>(LCMSTransform.java:122)
at sun.java2d.cmm.lcms.LCMS.createTransform(LCMS.java:76)
at java.awt.color.ICC_ColorSpace.fromRGB(ICC_ColorSpace.java:222)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(JPEGImageReader.java:635)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:550)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:295)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:427)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:543)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:986)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:966)
at javax.imageio.ImageIO.read(ImageIO.java:1448)
at javax.imageio.ImageIO.read(ImageIO.java:1400)
Is Java's image reader known to be fragile? Is there a more robust Java library for loading images?
Upvotes: 2
Views: 819
Reputation: 18601
Not sure what you're trying to do, what's exactly in your code, and which line throws a NullPointerException but the following works fins in Java 6:
String imageUrl = "http://taste-for-adventure.tablespoon.com/files/2012/02/2012-02-05-poll-hotdog-275w.jpg";
BufferedImage bi = ImageIO.read(new URL(imageUrl));
if(bi != null)
System.out.println("Image Loaded!");
else
System.out.println("Something's wrong...");
Sorry but I cannot test it in Java 7 right now...
Upvotes: 0
Reputation: 11215
Hi please try the following, This runs without any problem in java 1.6? Does it give the same exception?
import java.awt.BorderLayout;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ShowImage {
public static void main(String[] args) {
JFrame frame = new JFrame("Debug Frame");
frame.setSize(200, 200);
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Image image = null;
JLabel label = null;
try {
image = ImageIO.read(new File("c:/scratch/hotdog.jpg"));
label = new JLabel(new ImageIcon(image));
} catch (IOException e) {
label.setText("Image loading failed");
}
frame.add(label,BorderLayout.CENTER);
frame.setVisible(true);
}
}
Upvotes: 2