Problem loading image from jar file referenced by jar file

First, I searched this one and no, I didn't find an answer. Loading images from jar files has been pretty much done to death but my problem is different. Please read on.
I have my application, a straight up executable running from Eclipse. It uses a jar file, call it JarA. JarA launches a GUI that is located in another jar file. Call it JarB. To recap:
My application calls JarA -> JarA loads classes from JarB -> JarB looks for images to place in a GUI it wants to show on the screen
When JarB goes to load an image the following happens:
java.lang.NullPointerException
     at sun.misc.URLClassPath$3.run(URLClassPath.java:316)
     at java.security.AccessController.doPrivileged(Native Method)
     at sun.misc.URLClassPath.getLoader(URLClassPath.java:313)
     at sun.misc.URLClassPath.getLoader(URLClassPath.java:290)
     at sun.misc.URLClassPath.findResource(URLClassPath.java:141)
     at java.net.URLClassLoader$2.run(URLClassLoader.java:362)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findResource(URLClassLoader.java:359)
     at java.lang.ClassLoader.getResource(ClassLoader.java:977)
     at org.cubrc.gmshell.gui.MainWin.preInit(MainWin.java:152)
     at org.cubrc.gmshell.gui.MainWin.<init>(MainWin.java:135)
The code from JarB that loads the image looks like this:
          URL[] oSearch = {Main.class.getResource("images/")};
          URLClassLoader oLoader = new URLClassLoader(oSearch);
          imgIcon = new ImageIcon(oLoader.getResource("icon.gif"));
          imgMatchRunning = new ImageIcon(oLoader.getResource("gears.gif"));
          imgMatchStill = new ImageIcon(oLoader.getResource("gears-still.gif"));
          imgMagnify = new ImageIcon(oLoader.getResource("magnify.gif"));This looks right to me and JarB certainly has an images directory with those files. But I'm in hell right now because I don't know where to place the images to make this work or if you can even attempt to load images with a dependency chain like this.
Any help very appreciated!

Have you tried to move your image-files out of the jar file and place them in the sam folder as the jar-file? I think that would help.
When you try to load the image-file you get the NullPointerException because the program tries to read a file it can't find. Remember that a jar file IS a file and not a directory.
If you want to read somthing inside the jar-file you need to encode it first.
Have you tried to read the jar-file with winRar. It makes it easy to add and remove files in your jar-file.

Similar Messages

  • Problem loading images from a return value of a function

    hello, I write because I uin problem in loading images from a return value of a function.
    I created a database with a field "image" of type string, where I put the physical address of the image. I have written like this: {__DIR__ }foto.jpg
    Place the code, so you understand better
    function imageViewImage(): javafx.scene.image.Image {
    connetti();
    lass.forName(driverName);
    con = DriverManager.getConnection(url,user,"");
    stmt = con.createStatement();
    var richiesta:String = "SELECT image from viaggio WHERE id_viaggio=7";
    rs1 = stmt.executeQuery(richiesta);
    var result :String;
    rs1.next();
    risultato = rs1.getString("image");
    JOptionPane.showMessageDialog(null, result);
    var imagez = Image{
    url:"{result}";
    return imagez;
    The image is in the source code package
    First I connect to the database, run the query and I take the contents of the image.
    Can anyone help me?
    Is right to put in the database {__DIR__} foto.jpg or do I put only foto.jpg?

    Hello unkus_nob,
    I would rather suggest you to save only filename of that image like "foto.jpg" in database. And just concat it with the String variable containing "{__DIR__}".
    Actually the javafx compiler converts the {__DIR__} to the existing class directory path something like : "jar:file:/..../".
    var currentDir ="{__DIR__}";
    risultato = "{currentDir}{rs1.getString("immagine"})"; 
    var image = Image{
        url:risultato
    return image;--NARAYAN G.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem loading image (from JAR)

    Hi
    I was wondering why this code works when running the app in my IDE, but not once exported in a JAR file:
    public static BufferedImage loadDefaultCover()
              try
                   return ImageIO.read(new File("./images/default.png"));
              }catch(IOException e)
                   logger.severe("Failed loading default img: "+e.getMessage());
              return null;
         }     NOTE 1: The cover is located (project root)/images/default.png
    NOTE 2: It works when I have a folder named images (with the image in it) next to the JAR.
    NOTE 3: I tried:
    return ImageIO.read(new File("images/default.png"));
    return ImageIO.read(new File("/images/default.png"));Any ideas? Thanks!
    Andrew
    Edited by: Andrew_ on Jan 4, 2009 12:45 PM

    You can't use File references to access resources in a jar file (technically, they are not presen in the file system but part of a zip file). Instead, you can load those resources via the classloader:
    return ImageIO.read(getClass().getClassLoader().getResourceAsStream("images/default.png"));

  • Please have a look at this, problem loading images from jar.

    I made a post at the wrong place..
    Pleae have a look at it:
    http://forum.java.sun.com/thread.jsp?forum=422&thread=434524&tstart=0&trange=15

    Answer (hopefully not totally useless) posted over there.

  • Problem loading image from HTTPS

    I am having trouble loading an image in Java client , the image is coming from a secure server.
    My code looks as follows
    Image image = null;
    try
    // just substituting my image with the secure image I found on sun site
    URL url = new URL("https://www.sun.com/im/sun_logo.gif");
    image = getToolkit().getImage(url);
    catch(MalformedURLException e )
    System.err.println("invalid URL");
    if (image == null)
         System.err.println("null image");
    MediaTracker mediaTrack = new MediaTracker(this);
    try
         mediaTrack.addImage(image, 0);
         mediaTrack.waitForAll();
    } catch (InterruptedException ie)
    System.err.println("Interrupted Exception");
    if (mediaTrack.isErrorAny())
    System.err.println("Error loading the image");
    Initialy I got MalformedURLException but then I switched to jdk1.4.2 and set the following system property and got passed that part but now I am getting error when MediaTracker tries to load the image.
    System.getProperties().put("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    I need to know if there is a better way of loading the image and if possible without having to set the system property.
    Thank you

    Have you tried using the HttpsURLConnection class introduced in JDK 1.4?

  • IOException: Problem loading image

    Hi foreros
    What could be the reason behind an error like this IOException: Problem loading image except it cannot find the jar path for the images?
    Regards
    Tizha

    Without more information, I'd say there's not enough available RAM to load the image.

  • Issues with Loading Images from a Jar File

    This code snippet basically loops through a jar of gifs and loads them into a hashmap to be used later. The images all load into the HashMap just fine, I tested and made sure their widths and heights were changing as well as the buffer size from gif to gif. The problem comes in when some of the images are loaded to be painted they are incomplete it looks as though part of the image came through but not all of it, while other images look just fine. The old way in which we loaded the graphics didn't involve getting them from a jar file. My question is, is this a common problem with loading images from a jar from an applet? For a while I had tried to approach the problem by getting the URL of the image in a jar and passing that into the toolkit and creating the image that way, I was unsuccessful in getting that to work.
    //app is the Japplet
    MediaTracker tracker = new MediaTracker(app);
    //jf represents the jar file obj, enum for looping through jar entries
    Enumeration e = jf.entries();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    //buffer for reading image stream
    byte buffer [];
    while(e.hasMoreElements())
    fileName = e.nextElement().toString();
    InputStream inputstream = jf.getInputStream(jf.getEntry(fileName));
    buffer = new byte[inputstream.available()];
    inputstream.read(buffer);
    currentIm = toolkit.createImage(buffer);
    tracker.addImage(currentIm, 0);
    tracker.waitForAll();
    images.put(fileName.substring(0, fileName.indexOf(".")), currentIm);
    } //while
    }//try
    catch(Exception e)
    e.printStackTrace();
    }

    compressed files are not the problem. It is just the problem of the read not returning all the bytes. Here is a working implementation:
    InputStream is = jar.getInputStream(entry);
    ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
    try{
    byte[] buf = new byte[1024];
    int read;
    while((read = is.read(buf)) > 0) {
    os.write(buf, 0, read);
    catch(Exception e){
         e.printStackTrace();
         return null;
    image = Toolkit.getDefaultToolkit().createImage(os.toByteArray());
    This works but I think you end up opening the jar a second time and downloading it from the server again. Another way of getting the images is using the class loader:
    InputStream is = MyApplet.class.getResourceAsStream(strImageName);
    In this case, the image file needs to be at the same level than MyApplet.class but you don't get the benefit of enumerating of the images available in the jar.

  • PJC - Loading Images from JAR Files

    I'm developing a PJC class that involves loading images. I would like to be able to find and use an image contained in a JAR file just like the built-in Forms items do; not the JAR file where my class is contained but any external ones defined in the server archive settings.
    I have seen the loadImage method in the demo RolloverButton class but this only loads images from the class's JAR and not any others.
    Is there a VButton method or an Oracle loader class for finding image resources from the defined JAR archives? If not, could someone supply some code for achieving this.
    Thank you.

    Hi,
    the jar file name the images are in shouldn't matter for the code as long as the package name is preserved. If you want to see it with your own eyes, do the following
    1. Back up demo90.jar
    2. Create a copy of it and call it demo90img.jar
    3. Open demo90.jar in winzip and remove all images
    4. Open demo90img.jar and remove all Java classes
    5. add ,/forms90demo/jars/demo90img.jar to the archive_jini tag of a demo you want to test this on
    6. Run the application and see the images despite the fact they are now in a separate jar file. Note in the Jinitiator console that the new jar files are downloaded and replace the existing, cached, jars
    7. Run an application that doesn't have demo90img.jar configured to see that the images are missing.
    Frank

  • How to load images from css file in JavaFX 8

    I have this css file which loads images in JavaFX 8 application:
    #pill-left {
        -fx-padding: 5;
         -fx-border-image-source: url("/com/dx57dc/images/left-btn.png");
        -fx-border-image-slice: 4 4 4 4 fill;
        -fx-border-image-width: 4 4 4 4;
        -fx-border-image-insets: 0;
        -fx-border-image-repeat: stretch;
         -fx-background-color: null !important;
    #pill-left:selected { -fx-border-image-source: url("/com/dx57dc/images/left-btn-selected.png"); }
    #pill-left .label {
        -fx-text-fill: #d3d3d3;
        -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.75) , 0, 0.0 , 0 , -1 );
    #pill-left:selected .label {
        /* -fx-text-fill: black; */
        -fx-text-fill: white;
        -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );
    #pill-center {
        -fx-padding: 5;
         -fx-border-image-source: url("/com/dx57dc/images/center-btn.png");
        -fx-border-image-slice: 4 4 4 4 fill;
        -fx-border-image-width: 4 4 4 4;
        -fx-border-image-insets: 0;
        -fx-border-image-repeat: stretch;
         -fx-background-color: null !important;
    #pill-center:selected { -fx-border-image-source: url("/com/dx57dc/images/center-btn-selected.png"); }
    #pill-center .label {
        -fx-text-fill: #d3d3d3;
         -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.75) , 0, 0.0 , 0 , -1 );
    #pill-center:selected .label {
        -fx-text-fill: black;
        -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );
    #pill-right {
        -fx-padding: 5;
        -fx-border-image-source: url("/com/dx57dc/images/right-btn.png");
        -fx-border-image-slice: 4 4 4 4 fill;
        -fx-border-image-width: 4 4 4 4;
        -fx-border-image-insets: 0;
         -fx-border-image-repeat: stretch;
        -fx-background-color: null !important;
    #pill-right:selected { -fx-border-image-source: url("/com/dx57dc/images/right-btn-selected.png"); }
    #pill-right .label {
         -fx-text-fill: #d3d3d3;
        -fx-effect: dropshadow( one-pass-box , rgba(0,0,0,0.75) , 0, 0.0 , 0 , -1 );
    #pill-right:selected .label {
        -fx-text-fill: black;
        -fx-effect: dropshadow( one-pass-box , white , 0, 0.0 , 0 , 1 );
    The images are located at the Java package com.dx57dc.images
    In Java 7_25 this code works as expected but in JavaFX 8 b99 I get this error:
    ava.lang.NullPointerException
    at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:1129)
    at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:1598)
    at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1520)
    at com.sun.javafx.sg.prism.NGGroup.renderChildren(NGGroup.java:233)
    at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:199)
    at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:1249)
    at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:1598)
    at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1520)
    at com.sun.javafx.sg.prism.NGGroup.renderChildren(NGGroup.java:233)
    at com.sun.javafx.sg.prism.NGGroup.renderContent(NGGroup.java:199)
    at com.sun.javafx.sg.prism.NGRegion.renderContent(NGRegion.java:1249)
    at com.sun.javafx.sg.prism.NGNode.doRender(NGNode.java:1598)
    at com.sun.javafx.sg.prism.NGNode.render(NGNode.java:1520)
    at com.sun.javafx.tk.quantum.ViewPainter.doPaint(ViewPainter.java:99)
    at com.sun.javafx.tk.quantum.AbstractPainter.paintImpl(AbstractPainter.java:210)
    at com.sun.javafx.tk.quantum.PresentingPainter.run(PresentingPainter.java:95)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at com.sun.javafx.tk.RenderJob.run(RenderJob.java:58)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:129)
    at java.lang.Thread.run(Thread.java:724)
    D3D Vram Pool: 13,331,480 used (5.0%), 13,331,480 managed (5.0%), 268,435,456 total
    20 total resources being managed
    4 permanent resources (20.0%)
    1 resources locked (5.0%)
    7 resources contain interesting data (35.0%)
    0 resources disappeared (0.0%)
    D3D Vram Pool: 13,331,480 used (5.0%), 13,331,480 managed (5.0%), 268,435,456 total
    20 total resources being managed
    4 permanent resources (20.0%)
    1 resources locked (5.0%)
    7 resources contain interesting data (35.0%)
    0 resources disappeared (0.0%)
    D3D Vram Pool: 13,331,480 used (5.0%), 13,331,480 managed (5.0%), 268,435,456 total
    20 total resources being managed
    4 permanent resources (20.0%)
    1 resources locked (5.0%)
    7 resources contain interesting data (35.0%)
    0 resources disappeared (0.0%)
    What is the proper way to load images from css in Java 8?
    Ref
    How to load images from css file in JavaFX 8 - Stack Overflow

    There is nothing special to do - you execute the statement from your program just like any other SQL statement.  The only thing to be aware of are the privilege/permission issues:
    When loading from a file on a client computer:
    READ CLIENT FILE privilege is also required for the database user.
    Read privileges are required on the directory being read from.
    The allow_read_client_file database option must be enabled.
    The read_client_file secure feature must be enabled.
    Revoking these privileges is also the only way you can prevent a user from executing the statement.

  • Load image from a cursor .cur file.

    Hi all,
    I want to create a customized cursor, and I have a Microsoft cursor .CUR file. Can I load this .cur file as an image? - Thank you
    Edited by: trangkd on Aug 9, 2011 3:08 PM

    Hi,
    I've been google-ing up-and-down, but couldn't find any implementation of .cur and Java. If anyone has done so, please post... I was looking for an easy way i.e. couple lines of code to load image from a .cur file .. like we do with gif or jpeg out of the box. The JIMI has an extensive support of many other formats, and it will be an alternative if the graphics department won't give us a new set of cursor images in gif/jpg format.
    Thanks so much.

  • Loading image from jars only once in oracle forms 10g

    Hi,
    I have an oracle forms 10g application which loads image from a jar. Every time i click on a button "A" that loads the image "image" on another button "B" in the same screen, a message is displayed in the java console "Loaded image: jar:https://+IP+/forms/java/+myjar+.jar!/image.gif". So after 10 clicks, i get the same message displayed 10 times. In the form, i've called:
    SET_CUSTOM_PROPERTY(p_object_name, 1, 'IMAGE_NAME_ON', '/'||p_image_name);My question is the following:
    - is there a way to load this image once and use it later without having to load it every time i clik on "A"? if yes, how?
    P.S.: if this thread shouldn't be posted in this forum, please redirect me to the right one.
    Thanks in advance

    Ah okay.
    I'm using the rolloverbutton.jar (RollOver Button PJC) [RolloverButton.java -> authors: Steve Button, Duncan Mills].
    Here is the part concerning the IMAGE_NAME_ON function:
    // make sure we are in rollover mode
    enableRollover();
    log("setProperty - IMAGE_NAME_ON value=" + value.toString());
    // load the requested image
    m_imageNameOn = (String) value;
    loadImage(ON,m_imageNameOn);
    // reset the currrently drawn image if needed
    setImage(ON,m_state);
    return true;where loadImage function is:
        URL imageURL = null;
        boolean loadSuccess = false;
        //JAR
        log("Searching JAR for " + imageName);
        imageURL = getClass().getResource(imageName);
        if (imageURL != null)
          log("URL: " + imageURL.toString());
          try
            m_images[which] = Toolkit.getDefaultToolkit().getImage(imageURL);
            loadSuccess = true;
            log("Image found: " + imageURL.toString());
          catch (Exception ilex)
            log("Error loading image from JAR: " + ilex.toString());
        else
          log("Unable to find " + imageName + " in JAR");
        //DOCBASE
        if (loadSuccess == false)
          log("Searching docbase for " + imageName);
          try
            if (imageName.toLowerCase().startsWith("http://")||imageName.toLowerCase().startsWith("https://"))
              imageURL = new URL(imageName);
            else
              imageURL = new URL(m_codeBase.getProtocol() + "://" + m_codeBase.getHost() + ":" + m_codeBase.getPort() + imageName);
            log("Constructed URL: " + imageURL.toString());
            try
              m_images[which] = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              log("Image found: " + imageURL.toString());
            catch (Exception ilex)
              log("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            log("Error creating URL - " + urlex.toString());
        //CODEBASE
        if (loadSuccess == false)
          log("Searching codebase for " + imageName);
          try
            imageURL = new URL(m_codeBase, imageName);
            log("Constructed URL: " + imageURL.toString());
            try
              m_images[which] = createImage((java.awt.image.ImageProducer) imageURL.getContent());
              loadSuccess = true;
              log("Image found: " + imageURL.toString());
            catch (Exception ilex)
                    log("Error reading image - " + ilex.toString());
          catch (java.net.MalformedURLException urlex)
            log("Error creating URL - " + urlex.toString());
        if (loadSuccess == false)
          log("Error image " + imageName + " could not be located");In this case, what shall i modify?
    Thanks in advance

  • Problem – loading HTMLtext from a text file

    Problem – loading HTMLtext from a text file
    Hi, I have a dynamic text set up to render text as HTML and I
    am loading the text into the text object by using the code below.
    var loadText:LoadVars = new LoadVars();
    loadText.load("Nyheter.txt");
    loadText.onLoad = function(success){
    if(success){
    Nyheter_txt.htmlText = this.VariabelTekst;
    The textfile looks like:
    VariabelTekst=<p align
    ="Right">(13.11.2006)</p><p><b><font
    size="12">This is the tittle</b></p><p>Here
    comes the text</p>
    It works almost fine but the first problem is that the
    paragraph text in the textfile should be written in Norwegian. This
    involves some Nordic characters. By default these characters are
    just shown as small square in the text control when running the
    flash file. If I try to enter these characters in the textbox
    “Include these characters” within the dialog for
    embedding, the text within the bold tag of the text file is not
    shown when the text is rendered. It looks as if it effect the HTML
    rendering of the text. The Nordic characters are still not showing
    but instead the small square placeholders for the characters are
    gone.
    Am I doing it wrong, or is there a work around for solving
    this problem?
    Any ideas?
    TIRislaa

    Problem – loading HTMLtext from a text file
    Hi, I have a dynamic text set up to render text as HTML and I
    am loading the text into the text object by using the code below.
    var loadText:LoadVars = new LoadVars();
    loadText.load("Nyheter.txt");
    loadText.onLoad = function(success){
    if(success){
    Nyheter_txt.htmlText = this.VariabelTekst;
    The textfile looks like:
    VariabelTekst=<p align
    ="Right">(13.11.2006)</p><p><b><font
    size="12">This is the tittle</b></p><p>Here
    comes the text</p>
    It works almost fine but the first problem is that the
    paragraph text in the textfile should be written in Norwegian. This
    involves some Nordic characters. By default these characters are
    just shown as small square in the text control when running the
    flash file. If I try to enter these characters in the textbox
    “Include these characters” within the dialog for
    embedding, the text within the bold tag of the text file is not
    shown when the text is rendered. It looks as if it effect the HTML
    rendering of the text. The Nordic characters are still not showing
    but instead the small square placeholders for the characters are
    gone.
    Am I doing it wrong, or is there a work around for solving
    this problem?
    Any ideas?
    TIRislaa

  • How to load images from BLOB to javascript?

    hi, Guys:
    I need to load thumbnail images from BLOB to multiple markers' infowindow in Google map . I have implemented Google map in APEX. I load the data suchas text for every marker's infowindow from Oracle database table with PL/JSON, and infowindow works fine. Could anyone give me a suggestion or example so I know how to load images to javascript?
    Thanks a lot.
    Database: Oracle 11g R2
    APEX: APEX 4.1
    Thanks.
    Sam

    lxiscas wrote:
    hi, VC:
    Thanks for your kind reply. I need to render these images out of APEX session, actually in javascript that is related to Google map markers' infowindow.
    I checked the documents of APEX_UTIL.GET_BLOB_FILE_SRC, but my impression is I need to use it in APEX instead of javascript if my understanding is correct. I already implemented a procedure with PL/SQL to load images from a BLOB column in Oracle database. But the problem is, how can I pass it to javascript code out of APEX to javascript (I could pass text or number from APEX to javascript with PL/JSON though,But I assume that still google map will be within a valid apex session? if so you should be able to use the above api.
    Basically what this api does is generates a kind of url to each blob in the database, not sure how google api's deal with this though. Why don't you give it a try?
    The other option is to make your pl/sql procedure public and then you can generate the json to include the images urls such as:
         "employees" : [{
                   "firstName" : "John",
                   "lastName" : "Doe",
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
                   "firstName" : "Anna",
                   "lastName" : "Smith"
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
                   "firstName" : "Peter",
                   "lastName" : "Jones"
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
    }And then you can use this new attribute to populate the images in javascript using standard img tag
    See this tutorial http://docs.oracle.com/cd/E14373_01/appdev.32/e13363/up_dn_files.htm
    I did not find any method in PL/JSON to pass image object)? So far I only found example to load images from local files to javascript.Hmm..I don't think you should load image objects.
    Vikram

  • Problem loading images - please help

    Hi,
    I have a slight problem loading images. I'm using netbeans 5.0 and have a few packages setup in a project called Maths. In a package called LineConnection theres a class that needs to read an image and display it on screen. To load the image I use:
    URL url = getClass().getResource("fraction/pic1.png");
    Image img1 = Toolkit.getDefaultToolkit().getImage(url);This loads the image and I can display it on screen fine.
    The problem is that the folder fractions with the images in HAS to be located within the Maths/build/class/LineConnection folder otherwise it wont load the image and I get a null pointer exception.
    I want to be able to have the folder containing the images in folder Maths so that it's one folder above the src folder. But if I put it here (or anywhere else) the images can't be found and loaded.
    Could someone tell me why the images can only be found if they're within the build folder because it's causing me some problems when I try to create an executable JAR.
    Cheers

    I've used:
    URL url = ImageHandler.class.getResource("fractions/q0.png");               
    System.out.println("URL = " + url);to determine whether the file is found.
    If I put the file in the folder build/classes/LineConection/fractions/q0.png then it finds the image and prints the file path.
    But, if I put it in another folder such as the src folder it can't find the image and url = null;
    How can I make netbeans search in other folders for the resources so I can store them where I like?

  • How do i load images from a folder?

    Hello everyone,
    Please can someone help me as i am stuck.
    I am trying to research loading images from a folder called /images/unknown (unknown is a customer number and is stored in a variable called customerNo).
    I feel that i will need to load the images into an array then display them to the screen with a viewer.
    Can anybody help me.
    Thanks in advance

    Welcome to the Sun forums.
    irknappers wrote:
    ...Please can someone help me as i am stuck.You might want to be more exact in future, about what you are stuck on.
    import javax.imageio.ImageIO;
    import java.io.FileFilter;
    import java.io.File;
    import javax.swing.JFileChooser;
    class LoadImages {
        public static void main(String[] args) {
            String[] suffixes = ImageIO.getReaderFileSuffixes();
            FileFilter fileFilter = new FileFilterType(suffixes);
            File directory = null;
            if (args.length==1) {
                directory = new File( args[0] );
            } else {
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );
                int result = fileChooser.showOpenDialog( null );
                if ( result == JFileChooser.APPROVE_OPTION ) {
                    directory = fileChooser.getSelectedFile();
                } else {
                    System.err.println("Must select a directory to proceed, exiting.");
            File[] images = directory.listFiles( fileFilter );
            for (File file : images) {
                System.out.println(file);
            System.out.println( "The rest is left an exercise for the reader.  ;-)" );
    class FileFilterType implements FileFilter {
        String[] types;
        FileFilterType(String[] types) {
            this.types = types;
        public boolean accept(File file) {
            for (String type : types) {
                if ( file.getName().toLowerCase().endsWith( type.toLowerCase() ) ) {
                    return true;
            return false;
    }

Maybe you are looking for

  • Text input boxes same colour as background - so "invisible", and button text or buttons often missingt

    I have turned off all addons/extensions/plugins - still the same problem: 1: Text input boxes appear to be the same colour as the background - and hence "invisible" 2: Clickable buttons on websites are often invisible, or if they display have no text

  • Printing 2 notifications in 1 page

    Hi All, I need to print two notifications in one page. One notification will only printed at half the page while the 2nd notification will be printed on the other half page. Lets say if I selected multiple print job (eg 100 notification) , and 50 pag

  • Data usage gone crazy

    Has anybody else in the last couple of days received a notification that they went over their data plan when their usual usage is not even close to 2gb? I've had a couple of people telling me this is happening to them just like it happened to me.

  • Passing Parameter to SAP Transaction via AppIntegrator

    Hi, I created an AppIntegrator iView that calls a R/3 Transaction. The iView is running correctly. Now I want to pass a dynamic parameter to the Transaction so that it skips the first screen of the transaction. For this purpose there is the iView Par

  • Approval Process in the workflow

    Hi, in the current approval process, where the user receives a notification and then when the user clicks the approve button, it will build up another email and with all the messages and the user needs to click "send" to send the email, this is in Mi