Javax.imageio.IIOException: Can't read input file!

That is the error I get every time I try to run the .jar file. Yet when I run it in the compiler it works just fine. I'm not sure what to make of this, here is the code any help you can provide will be appreciated.public void setGraphic(String image) {
        String fileLoc = getClass().getResource("/com/siteName/Graphics/" + image).getPath();
        try {
            fileLoc = URLDecoder.decode(fileLoc,"UTF-8");
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
        File file = new File(fileLoc);
        try {
            this.image = ImageIO.read(file);
        } catch (IOException ex) {
            ex.printStackTrace();
}

Is your image in the jar? If so, use URL, not File:
URL url = getClass().getResource("/com/siteName/Graphics/" + image);
this.image = ImageIO.read(url );

Similar Messages

  • IIOException: Can't read input file!

    Hi all,
    I have a incomprehensible problem. I have a java application wich manipulate images. This application works fine with a desktop environment but when I try to migrate it on production server (without X), a exception is catch...
    javax.imageio.IIOException: Can't read input file!
            at javax.imageio.ImageIO.read(ImageIO.java:1279)
            at FaceplateBuilder.fillImageByClients(FaceplateBuilder.java:95)
            at FaceplateBuilder.createPack(FaceplateBuilder.java:68)
            at FaceplateBuilder.run(FaceplateBuilder.java:39) This is the following code...
    File tmp = new File("/tmp/test.jpg");
    BufferedImage in = ImageIO.read(tmp);The file /tmp/test.jpg exist.
    Here are all tested solutions without success :
    *I've tried to upgrade the java version (1.5.0_14 to 1.6.0_06). 1.6.0_06 is the desktop environment configuration.
    * I read this page: [Using Headless Mode in the Java SE Platform|http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/] and I try to launch java with java.awt.headless=true variable.
    * I have install the [X11 dev library|http://javatechniques.com/public/java/docs/hosting/headless-java-x11-libraries.html]. (apt-get install libice-dev libsm-dev libx11-dev libxp-dev libxt-dev libxtst-dev)
    * I have changed the ImageIO code by following :
    Image tmp = loadImageFile("/tmp/test.jpg");
    BufferedImage in = toBufferedImage(tmp);
    public static BufferedImage toBufferedImage(Image image) {
              if (image instanceof BufferedImage) {
                   return ((BufferedImage) image);
              } else {
                   BufferedImage bufferedImage = new BufferedImage(image
                             .getWidth(null), image.getHeight(null),
                             BufferedImage.TYPE_INT_RGB);
                   Graphics g = bufferedImage.createGraphics();
                   g.drawImage(image, 0, 0, Color.WHITE, null);
                   g.dispose();
                   return (bufferedImage);
         public static Image loadImageFile(String imgFile) {
              Image img = Toolkit.getDefaultToolkit().getImage(imgFile);
              MediaTracker mediaTracker = new MediaTracker(new Container());
              mediaTracker.addImage(img, 0);
              try {
                   mediaTracker.waitForID(0);
              } catch (InterruptedException e) {
                   e.printStackTrace();
                   System.out.println(e.getMessage());
              return (img);
         }This code catches a new error...
    java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
            at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
            at java.awt.image.BufferedImage.<init>(BufferedImage.java:314)
            at FaceplateBuilder.toBufferedImage(FaceplateBuilder.java:122)
            at FaceplateBuilder.fillImageByClients(FaceplateBuilder.java:95)
            at FaceplateBuilder.createPack(FaceplateBuilder.java:73)
            at FaceplateBuilder.run(FaceplateBuilder.java:44)I think it's the same problem... The Image can't be loaded and I don't know why ! This problem make me crazy so I tried to post here.
    Thanks in advance

    # la /tmp/test.jpg
    -rw-r--r-- 1 root root 148K 2008-07-15 13:19 /tmp/test.jpg
    # ps aux | grep java
    root     19147  0.0  1.8 269716 23848 pts/1    Ssl+ 19:09   0:00 java FaceplateManager     Everything seems good :)

  • ImageIO - javax.imageio.IIOException: Can't get input stream from URL

    Hi,
    I'm developing a program which accesses a given URL of an image and saves it to a file. However when I try this I get the following error:
    javax.imageio.IIOException: Can't get input stream from URL!
         at javax.imageio.ImageIO.read(Unknown Source)
         at ImageSave.main(ImageSave.java:12)
    Caused by: java.net.ConnectException: Connection timed out: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(Unknown Source)
         at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
         at java.net.PlainSocketImpl.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at java.net.Socket.connect(Unknown Source)
         at sun.net.NetworkClient.doConnect(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.openServer(Unknown Source)
         at sun.net.www.http.HttpClient.<init>(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.http.HttpClient.New(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
         at java.net.URL.openStream(Unknown Source)
         ... 2 moreThe internet connection I am using uses a proxy server and I think this is where the problem lies. I'm using Eclipse version 3.3 and I've tried changing the network settings to use the proxy's hostname and port but this still isn't working. I've also tried using System.setProperty("http.proxyHost", "hostname") and System.setProperty("http.proxyPort", "port") but that hasn't worked for me either. Below is my class in full.
    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.*;
    import java.net.*;
    public class ImageSave
         public static void main(String args[])
              try {
                   URL url = new URL("http://www.example.com/image.jpg");
                   BufferedImage image = ImageIO.read(url);
                   ImageIO.write(image, "JPG", new File("image.jpg"));
              catch (Exception e) {
                   e.printStackTrace();
    }The error occurs with the line: BufferedImage image = ImageIO.read(url);
    I have tried looking for a way to change how this specific method accesses the internet (e.g: a Proxy parameter with URLConnection) but there doesn't seem to be any.
    Any help or suggestions would be greatly appreciated.
    -Robert

    Ah, that worked fine. I had thought of using that earlier but I was under the impression that the input stream would be HTML rather than an actual image. Not sure why.. Anyway, thanks very much for your help!
    Here is the new code with your suggested revisions and a URLConnection to get the input stream:
    import java.awt.image.*;
    import javax.imageio.*;
    import java.io.*;
    import java.net.*;
    public class ImageSave
        public static void main(String args[])
            try {
                 // This is where you'd define the proxy's host name and port.
                 SocketAddress address = new InetSocketAddress(hostName, port);
                 // Create an HTTP Proxy using the above SocketAddress.
                 Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                 URL url = new URL("www.example.com/image.jpg");
                 // Open a connection to the URL using the proxy information.
                 URLConnection conn = url.openConnection(proxy);
                 InputStream inStream = conn.getInputStream();
                 // BufferedImage image = ImageIO.read(url);
                 // Use the InputStream flavor of ImageIO.read() instead.
                 BufferedImage image = ImageIO.read(inStream);
                 ImageIO.write(image, "JPG", new File("image.jpg"));
            catch (Exception e) {
                 e.printStackTrace();
    }Edited by: Ragnarob on Apr 21, 2009 2:49 AM

  • Javax.imageio.IIOException: Insufficient memory (case 2)         at com.sun

    javax.imageio.IIOException: Insufficient memory (case 2)
    at com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage(J[BIII[IIIIII[Ljavax.imageio.plugins.jpeg.JPEGQTable;Z[Ljavax.imageio.plugins.jpeg.JPEGHuffmanTable;[Ljavax.imageio.plugins.jpeg.JPEGHuffmanTable;ZZZI[I[I[I[I[IZI)Z(Native Method)
            at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:971)
            at javax.imageio.ImageWriter.write(ImageWriter.java:598)
            at javax.imageio.ImageIO.write(ImageIO.java:1450)
            at javax.imageio.ImageIO.write(ImageIO.java:1515)
            at jsp_servlet._css.__code._jspService(__code.java:145)
            at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
            at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
            at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:230)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    <img border=0 src="code.jsp">
    the content of JSP file about:
    <%@ page import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*"%>
    <%@ page import="java.io.OutputStream"%>
    <%@ page pageEncoding="UTF-8"%>
    <%!Color getRandColor(int fc, int bc) {   
    Random random = new Random();
    if (fc > 255)
    fc = 255;
    if (bc > 255)
    bc = 255;
    int r = fc + random.nextInt(bc - fc);
    int g = fc + random.nextInt(bc - fc);
    int b = fc + random.nextInt(bc - fc);
    return new Color(r, g, b);
    %>
    <%
    try {  
    out.clearBuffer(); // 加上这一句
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setDateHeader("Expires", 0);
    int width = 70, height = 20;
    BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
    OutputStream os = response.getOutputStream();
    Graphics g = image.getGraphics();
    Random random = new Random();
    //设置背景和大小
    g.setColor(getRandColor(200, 250));
    g.fillRect(0, 0, width, height);
    //设置字体和颜色
    g.setFont(new Font("Times New Roman", Font.BOLD, 20));
    g.setColor(getRandColor(120, 200));
    for (int i = 0; i < 50; i++) {   
    int x = random.nextInt(width);
    int y = random.nextInt(height);
    int xl = random.nextInt(5);
    int yl = random.nextInt(5);
    g.drawLine(x, y, x + xl, y + yl);
    String sRand = "";
    for (int i = 0; i < 4; i++) {
    String chose="0123456789";
    String rand = String.valueOf(chose.charAt(random.nextInt(chose.length())));
    sRand += rand;
    g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
    g.drawString(rand, 15 * i + 6, 16);
    session.setAttribute("rand", new String(sRand));
    g.dispose();
    g=null;
    ImageIO.write(image, "JPEG", os);
    os.flush();
    os.close();
    os = null;
    response.flushBuffer();
    out.clear();
    out = pageContext.pushBody();
    } catch (IllegalStateException e) {   
    System.out.println(e.getMessage());
    e.printStackTrace();
    %>

  • I am trying to import cr2files from the camera into lightroom 5 and keep getting an error message saying Lightroom can not read the files and therefore will not import them.  Has anyone had a similar problem-.thanks

    I am trying to import cr2files from the camera into lightroom 5 and keep getting an error message saying Lightroom can not read the files and therefore will not import them.  Has anyone had a similar problem….thanks

    If you are having the same problem, i.e. a disk permission problem, open your favorite search engine and search on, "change disk permissions", and I think you'll find plenty of information on how to fix the problem. This is a Lightroom forum. Your problem is with your operating system. There is no sense in rewriting instructions that are already available if you do a simple search.

  • How can I read pdf files from LabVIEW with different versions of Acrobat reader?

    How can I read pdf files from LabVIEW with different versions of Acrobat reader?
    I have made a LabVIEW program where I have possibility to read a PDF document.  When I made this LabVIEW program it was Acrobat Reader 5.0.5 that was installed on the PC. Lather when the Acrobat Reader was upgraded to version 6.0, there was an error when VI tries to launch the LabVIEW program. And Later again when we upgraded to Acrobat Reader 7.0.5 I must again do some changes and rebuild the EXE files again
    It isn't so very big job to do the changes in one single LabVIEW program, but we have built a lot of LabVIEW programs so this take time to due changes every time vi update Acrobat Reader. (We have build EXE files.)
    The job is to right click the ActiveX container and Click "Insert ActiveX Object", then I can brows the computer for the new version of acrobat Reader. After this I must rebuild all the "methods" in the Activex call to make the VI executable again.
    Is there a way to build LabVIEW program so I don't have to do this job every time we update Acrobat Reader?
    This LabVIEW program is written in LabVIEW 6.1, but I se the problem is the same in LabVIEW 8.2.
    Jan Inge Gustavsen
    Attachments:
    Show PDF-file - Adobe Reader 7-0-5 - LV61.vi ‏43 KB
    Read PDF file.jpg ‏201 KB
    Show PDF-file - Adobe Reader 5-0-5 - LV61.vi ‏42 KB

    hi there
    try the vi
    ..vi.lib\platform\browser.llb\Open Acrobat Document.vi
    it uses DDE or the command line to run an external application (e.g. Adobe Acrobat)
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"

  • How can I read a file with ASCII Special Character into a SQL table using SSIS 2008?

    I've tried everything to read this file and am getting no where.   Help how can I read this file and load a SQL table?
    RS - AscII - 30  (Record Separator)
    GS - AscII - 29 (Group Separator)
    Thank you for your assistance - Covi
    Mark Covian

    We can use script component as source/transformation to read the text file and assign the contains to a string. Split the string by chr(30)  i.e RS and finally stored into an array or write to the output buffer of the script component.
    For example on how to use script component refer this link
    http://social.technet.microsoft.com/Forums/en-US/6ff2007d-d246-4107-b77c-624781baab38/how-to-use-substring-in-derived-column-in-ssis?forum=sqlintegrationservices
    Regards, RSingh

  • Hi there, I need to be able to read raw files from an Olympus Stylus 1 via CS5 and Lightroom 4.  I have downloaded Raw file plug-in v 6.7.1 but still can't read the files.

    Hi there, I need to be able to read raw files from an Olympus Stylus 1 via CS5 and Lightroom 4.  I have downloaded Raw file plug-in v 6.7.1 but still can't read the files?

    Read this table http://helpx.adobe.com/creative-suite/kb/camera-raw-plug-supported-cameras.html
    The Olympus Stylus 1 was first supported in Camera Raw 8.3 which is only compatible with CS6 and CC.
    It is not compatible with CS5 or older and never will be.
    If you do not want to upgrade to CS6 or CC then you can dwonload the free Adobe DNG converter, convert all Stylus 1 Raw files to DNGs then edit the DNGs in CS5.
    Camera raw, DNG | Adobe Photoshop CC

  • How can I read text files from LAN if I only know the hostname?

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    <p>1. How can I read text files from LAN if I only know the hostname, or IP address?
    <p>2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.
    (ex. how can I read the 120th line?)
    <p>Please help!
    <p>sorry for the bad english

    I'm new in Java Developing, and dont know the written classes yet. I need help, how to do the following steps?
    1. How can I read text files from LAN if I only know the hostname, or IP address?You need to know the URL of the file. You need to know the hostname, port, protocl and relative path.
    The hostname is server, not file.
    2. How to read lines from text files without read all lines from the beginning of file, just seek to a position.Use the seek() to get to a random byte.
    (ex. how can I read the 120th line?)The only way to find the 120th line is to read the first 120 lines. You can use other file formats to find the 120th line without reading the whole file but to need to be able to detremine where the 120th line is

  • I can't read a file with the ext PDF the sender informed me that the file was reset to PDF.

    I can't read a file with the .ext PDF the sender informed me that the file was reset to PDF. But when I tried to open it the caption box informed me"the file is not in PDF format. I suspect the sender simply changed the file .ext which is why I can't open it! What can I do about it! I am working on an iPad.
    Thanks
    Mr Jim Lapthorn

    If the document is not, in fact, a PDF, then you will need to get your sender to provide a PDF.
    Can you open this document in any other application?

  • I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    I have a problem with the mac can not read video files with the extension IMOD. How can I solve this problem?

    By doing a Google search. 

  • My light room 5 can't read my files on my iMac and MacBook Pro any help pls

    my light room 5 can't read my file on my MacBook Pro and my iMac I already update my camera raw on ps cs6  any help with this issue pls

    If the error message is “files cannot be read” then this is usually a problem with the destination at the right of the destination import panel.
    If the issue is something different than not being able to import then please give a more detailed description.

  • Missing or can't read a file

    When I start iTunes there is standing right in the corner in a balloon
    \ipod_control\itunes\temp file 2
    is missing or can not be read please use the progam: CHKDSK
    And then i use that progam but he is stil missing or can't read the file?

    No - not Reset - Restore...? (using iPod Updater: http://docs.info.apple.com/article.html?artnum=60983)
    That usually works for the folks we've been chatting to...
    Cheers,
    Gopha.

  • I removed chrome 10 and newly installed FF4 final, and I can't read PDF files within the browser. There was no problem in Chrome.

    I removed chrome 10 and newly installed FF4 final, and I can't read PDF files within the browser. There was no problem in Chrome. I can't even see the acrobat reader plugin in the plugins page. Acrobat 10 is already installed in my PC. Every time I try to read a PDF file on the web, FF tries to download it instead.

    As recommended above by Bernd Alheit, I posted this on the Adobe Reader forum. There, I received the advice to repair the installation under the help menu, which I did and it fixed the problem.
    Similar to your solution but found it's a fix found under "HELP" menu and not Add/Remove.
    Thank you.

  • New pc with windows 8.1, downloaded and installed cs5,no problem open bridge and cs5, but can't read raw file , try to update, can't complete or failed updating, please help

    new pc with windows 8.1, downloaded and installed cs5,no problem open bridge and cs5, but can't read raw file , try to update, can't complete or failed updating, please help

    Sounds like you somehow got the mac version.
    Download the windows 6.7 camera raw update from this link:
    Adobe - Photoshop : For Windows : Camera Raw 6.7 Update

Maybe you are looking for

  • External drive for Time Machine and Firewire Hub

    Just got a new iMac. My old iMac G5 was running 10.4.11 so no Time Machine. On the new iMac I am running 10.5.6 I find I have questions about how to go about making best use of this new facility available to me. Since my new iMac has only one firewir

  • Agent Dashboard

    Hi All, can you please tell where I can enter the phonenr in the Agent dashboard or does it come directly from the CTI System? lookt at the picture I sent.

  • How to change Un formatted XML to Formatted XML in SSRS ?

    Hi Friends, I have an issue with SSRS report when exporting it into xml , it's showing un formatted xml like below but my requirement is it has to show formatted xml like below Please help me with this issue, NOTE: here i am building reports on Cube.

  • Upgrading ODI 11.1.1.7  Repositories to 12C

    Hi Friends, Does anybody has any clue to resolve the below error? This error comes at the time of calling ua.bat (12 C ) in CMD. I am trying my best to resolve this but it will be really appreciated for any suggestions on this. Thanks Bhabani java.la

  • Oracle Management Server fails to start on Solaris 8

    I'm trying to start OMS for oracle9i on a Solaris 8 machine. I type the following command to start OMS; oemctl start oms OMS then tries to start and after a minute it times out saying look at file $ORACLE_HOME/sysman/log/oms.nohup. When I do this I s