Jar file not showing images

Hi
When I make a runable jar file, my images it not showing if I try it on another computer. I searched the net and most people seems to use URLs instead ImageIO. But that doesnt help me either. Then I get the error message: Uncaught error fetching image:
java.lang.NullPointerException
Code is below. I hope someone can tell me what I should do.
    private Show show;
    private final int unit = 32;    // size of the images
//    private BufferedImage free;
    private Image free;
    private BufferedImage booked;
    private BufferedImage toBeBooked;
    private BufferedImage ableToEdit;
    public TheaterOverview(Show show)
        this.show = show;
//        try
//            free = ImageIO.read(new File("src/images/user_alt2.png"));
//            booked = ImageIO.read(new File("C:/Documents and Settings/Mads/Programmering/Eclipse/workspace/BioBooking/src/images/user_alt.png"));
//            toBeBooked = ImageIO.read(new File("C:/Documents and Settings/Mads/Programmering/Eclipse/workspace/BioBooking/src/images/user.png"));
//            ableToEdit = ImageIO.read(new File("C:/Documents and Settings/Mads/Programmering/Eclipse/workspace/BioBooking/src/images/user-yellow.png"));
//        catch (Exception e)
//            System.out.println("Not able to read images " + e);
        try
            URL myurl = this.getClass().getResource("images/user_alt2.png");
            Toolkit tk = this.getToolkit();
            free = tk.getImage(myurl);
//            free = ImageIO.read(new File("images/user_alt2.png"));
            booked = ImageIO.read(new File("images/images/user_alt.png"));
            toBeBooked = ImageIO.read(new File("images/images/user.png"));
            ableToEdit = ImageIO.read(new File("images/images/user-yellow.png"));
        catch (Exception e)
            System.out.println("Not able to read images " + e);
     * The paint method. Checks what the status is of each seat and draws them accordingly.
    public void paint(Graphics g)
        Show show = getShow();
        int numberOfRows = show.getTheater().getNumberOfRows();
        int numberOfSeatsInRow = show.getTheater().getSeatsPerRow();
        for (int i = 0; i < numberOfRows; i++)
            for (int j =0; j < numberOfSeatsInRow; j++)
                Seat seat = getShow().getRow(i).getSeat(j);
                if(seat.isAbleToEdit())
                    g.drawImage(ableToEdit, j*unit+1, i*unit+1, null);
                else if (seat.isBooked())
                    g.drawImage(booked, j*unit+1, i*unit+1, null);
                else if (!seat.isBooked() && !seat.isSelected())
                    g.drawImage(free, 0, 0, this);
                else if (seat.isSelected())
                    g.drawImage(toBeBooked, j*unit+1, i*unit+1, null);
    }

just work on getting one simple image to .jar OK
e.g. this should .jar OK (after changing image names)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
  Image img;
  public void buildGUI()
    try
      java.net.URL url = new java.net.URL(getClass().getResource("Test.gif"), "Test.gif");
      if(url != null) img = javax.imageio.ImageIO.read(url);
    catch(Exception e){}//swallow exception - handled in paintComponent
    JPanel p = new JPanel(){
      public void paintComponent(Graphics g){
        super.paintComponent(g);
        if(img != null) g.drawImage(img,100,100,this);
        else g.drawString("this space for rent",100,100);
    JFrame f = new JFrame();
    f.getContentPane().add(p);
    f.setSize(400,300);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Testing().buildGUI();
}put the image in the same folder, make .jar, then try the .jar on another pc
if all OK, change code to locate image file in subfolder, make .jar, then try the .jar on another pc
if all OK now, modify main program accordingly.
note: in .jars, capitalization of the image file names counts
e.g. in my above example, if I change Test.gif to test.gif, the image is not drawn

Similar Messages

  • How to delete a jar file after loading image files from it

    Hi,
    How can I delete a jar file after some image files have been loaded? For example, say, I have "a.jar" which contains an image "a.gif" in the root directory of the c drive. I would like to get the image size and then delete the jar file. Here is the code snippet:
        URL url = new URL("jar:file:/C:\\a.jar!/a.gif");
        Icon icon = new ImageIcon(url);
        System.out.println("icon size ? " + icon.getIconHeight());
        File file = new File("c:\\a.jar");
        while(file.exists())
            file.delete();
            try
                Thread.sleep(100);
            catch (InterruptedException ignored)
        System.out.println("file deleted.");I get the image size correctly but just can not delete the jar file. Apparently the file handle is not released, but how to close it? Any hint will be appreciated.
    Justin Jan

    I am sure the URLConnection.defaultUseCaches is set before it is connected otherwise I should catch an IllegalStateException on conn.setUseCaches(false).
            try
                URL url = new URL("jar:file:/C:\\a.jar!/a.gif");           
             URLConnection conn = url.openConnection();
               conn.setDefaultUseCaches(false);
             conn.setUseCaches(false);
                Icon icon = new ImageIcon(url);
                System.out.println("icon size ? " + icon.getIconHeight());
                url.openConnection().getInputStream().close();
                System.gc();
             System.runFinalization();
                File file = new File("c:\\a.jar");
                while (file.exists())
                    file.delete();
                    try
                        Thread.sleep(10);
                    catch (InterruptedException ignored)
                System.out.println("file deleted.");
            catch (Throwable t)
                t.printStackTrace();

  • Jdeveloper visual editor do not show images and other component shapes

    I used jdeveloper(10.1.3.3.0) to create an ADF BC application, I create a jsf jsp file and drag and drop components from ADF Faces Core to this file visual editor, but jdeveloper visual editor do not show images and other component shapes.
    Could you tell me how I can fix this problem?
    Thanks,
    Mike

    Actually, I need to make a dummy change to the jsp file and then it will display boxes representing the objects in the visual editor whereas I get an exception in the log:
    javax.servlet.jsp.JspException: Cannot find FacesContext
    This does not talk much to me !
    Thanks

  • Mobile Safari not showing images

    Hi there,
    Since upgrading to 4.01 and then 4.02 on my iPhone, Safari seems to intermittently not show images on websites... does anyone know the reason for this and a solution?

    I am having the same issue. I have found in my case the site I was working on is pulling content from JSON and the mobile app is using a Cache Manifest file. When I removed the manifest file reference I could see the images again.
    Message was edited by: Adam Randlett

  • JList not showing images

    Have raised a thread giving details of the problem in Java2D forum
    JList not showing images
    Have anybody experienced this issue? I face this issue only when i use swingworker and only for small images (few kBs). It works fine for large images (More than 1MB files). I use Win 7.
    Regards,
    Sreram

    One, do you say because i set the model each time, sometimes the list is not getting repainted? I didn't say that. It's just good concurrency practice to only manipulate models on the EDT, particularly when SwingWorker easily allows the break up of loading the images in a background thread and updating the model on the EDT through the publish/process methods.
    Will the splitting up of worker as process chunks be of any use? Again it's just a good habit to get into for concurrency reasons.
    As for your repainting issue, try changing this line
    item.setImage(getImagefromFile(f)); to
    item.setImage(new ImageIcon(getImageFromFile(f)).getImage()); The ImageIcon class uses MediaTracker to synchronously load images (you can use your own if you want). If you're getting your images via the Toolkit.createImage# methods, then the images need to be loaded. Usually what happens is the toolkit image will get loaded when first drawn. The component that's doing the drawing gets repainted as more of the image comes in. But in the case of a JList, that component is the cell renderer pane and it doesn't care about repaint() calls. So changing the above line will insure the images are already loaded and ready to draw when first shown. tjacobs01 post reminded me of this.

  • External Drive Files Not Showing Up on Mac but files do shows Up on PC

    External Drive Files Not Showing Up on Mac but files do shows Up on PC
    i had the Ex HD for about 3 years running smoothly on my mac but recently everything disappeared. plunged it into a pc to see if it read my files and it did. what can i do? to make it work on mac again. i don't want to reformat that drive because i have important applications (DMG) and other zip photo video files in the drive.

    yes. i did.
    ...i have tried "verify" & "repair" but they didn't pass the san test. and when i "unmounted/mount" a error message popped up say that there is a application running off the drive but there nothing (i see) running, to close all activity

  • My mac will not show images when on the internet?

    My mac will not show images when on the internet?  I think I have inadvertently changed some settings but nor sure which one.

    I am going to assume you are using Safari here. If so then go to the Apple menu bar and hit Safari-> Preferences.  Under the Apperance tab there is a check box that is called "Display images when the page opens".  Check if that is unticked.

  • File not showing in SharePoint (IE) but visible in Explorer

    I have a document library that has a single file not showing up that I can't seem to track down.  I am hoping someone here might be able to offer something I haven't thought of. 
    The document library is very much 'stock'.  Verisioning is turned on and minor revisions aren't viewable to folks without edit rights.  I am the admin with full control to everything - as is the user this initially impacted. The file will show
    in the Explorer view - but isn't viewable in an 'all files' file via the browser or when attempting to open via Excel.   If we provide the full path/file it does open successfully in Excel and offer the Check Out option - but it won't show up
    in the 'File Open' dialog.  
    I thought at first it might be a matter of not having a version checked in - but it isn't showing under "Manage files which have no checked in version" menu.   I've gone through the various SharePoint view options and can't find anything there either. 
    What would make a single Excel file in such an ordinary document library not be visible to users with full control rights?  We have roughly 80k files stored in SharePoint overall - so please don't read this as being our initial test of SharePoint. 
    I'd really appreciate any ideas... 
    -Troy

    Just to add a few more details. I have been able to add the file to a different library and they uploaded fine. The library in question is created off of a template and has 2 metadata fields. The fields are also being used in the other library, but that
    was created from a different template.
    The site and initial 4 libraries were created from a site template and then the library was added from a different library template. Checking ULS logs now, but doubtful I will find anything.

  • Error:verifier jar file not found

    Hi,
    I found problem "verifier jar file not found" while building a package in Aspects Developer Evaluation version.
    Pls guide me regarding my problem if any body could.

    Include the offcardverifier.jar file in your classpath, you will find this file under $java_card_kit-2_2_2\lib
    Regards,
    Amr.

  • HT4101 I am trying to connect my JVC Hard Disk Drive Camcorder to my IPAD 2 via the Apple camera kit. I am able to down photos, but video files not showing. Camera shows Mass Stoarge. How can I download videos please.

    I am trying to connect my JVC Hard Disk Drive Camcorder to my IPAD 2 via the Apple camera kit. I am able to download photos, but video files not showing. Camera shows Mass Stoarge. How can I download videos please?

    The file name only has 6 characters and I'm not sure what the .mod format is. So that's why they are not seen by the iPad.
    Another way to transfer. You can use a USB flash drive & the camera connection kit.
    Plug the USB flash drive into your computer & create a new folder titled DCIM. Then put your movie/photo files into the folder. The files must have a filename with exactly 8 characters long (no spaces) plus the file extension (i.e., my-movie.mov; DSCN0164.jpg).
    Now plug the flash drive into the iPad using the camera connection kit. Open the Photos app, the movie/photo files should appear & you can import. (You can not export using the camera connection kit.)
    Secrets of the iPad Camera Connection Kit
    http://howto.cnet.com/8301-11310_39-57401068-285/secrets-of-the-ipad-camera-conn ection-kit/
     Cheers, Tom
    Look at this link for convertion the .mod format.
    http://www.makeuseof.com/tag/convert-mod-camcorder-video-format-mpg-instantly/
    Message was edited by: Texas Mac Man

  • IPhoto files not showing up in list

    I have many photos on my new MacBook Pro, but when I try to "attach" them to emails, they are not showing up in the listing. I am a new Mac user, but so I don't know how to explain this. If this was a PC, it would be like files not showing up under "My Computer." PhotoBooth photos are listed though. Why is this?

    Then something has happened to the permission and or attribute settings on your folders to mark files saved in them as hidden.
    Try this Terminal command to show all files and you can turn it off by changing the true to false at the end of the command.
    defaults write com.apple.finder AppleShowAllFiles -bool true
    If you then see your files tere is a problem with files being market as hidden when they are saved. Create a New Folder in the Root of the drive and look at its Get Info window and post a screen shot of it in this thread.

  • Files not showing up in folders

    Files not showing up in folders. Saving files to folders, opening folders which are blank

    Then something has happened to the permission and or attribute settings on your folders to mark files saved in them as hidden.
    Try this Terminal command to show all files and you can turn it off by changing the true to false at the end of the command.
    defaults write com.apple.finder AppleShowAllFiles -bool true
    If you then see your files tere is a problem with files being market as hidden when they are saved. Create a New Folder in the Root of the drive and look at its Get Info window and post a screen shot of it in this thread.

  • Imported Jar file not loaded at run time ORA-105100

    Oracle 9iDS forms Version 9.0.2.9.0
    Oracle 9iAS Release 2
    I have imported java classes from a jar file into my form. I have it working in client server. Added the entries to the classpath in the default.env and system environment variable for development of the form and for execution.
    Moved the jar file, form and testing html to the application server. Modified the classpath in the default.env file. Tested the form. Got the ORA-105100 error. MetaLink note 261650.1 states that error frm-40735 When-Button-Pressed triger raised exception ORA-105100 if calling a java function from a jar file. Cause: Jar file not loaded at run time. Solution: add in your default.env CLASSPATH parameter your jar file including the whole directory of the jar file location. That has been done and the OC4J has been restarted. Still get error.
    Oracle support has not been able to give me much help as of yet. Does anyone have any further ideas, or documentation that I can read to help get this working?
    Thanks in advance for any assistance that is offered.

    Hey people any clues?

  • Why will my java.jar file not open

    Why will my java.jar file not open

    This is the iPod touch forum. Do you have a question concerning an iPod touch? The iPod touch does not run Java.
    If you have a new Mac you have to download the Java program to run Java on a Mac. It no longer comes with the iOS.

  • Amazon and FaceBook not showing images

    I had a software issue and had to wipe my macbook. Since then, Safari will occasionally not show images on Amazon and sometimes FaceBook. Usually a clean of the history will fix it but sometimes it doesn't. I am not running any extensions and everything is up to date. Any idea what could be causing this?

    Hello Clement! (Be careful in what you post to the Internet, your name is in the screenshot, just sayin' If you want to be able to blur things in screenshots before posting them, try Skitch, it's a free app on the Mac App Store)
    In the past, I've seen this being caused by ISP's DNS servers.
    Try the following:
    Unplug your modem from the power, wait a minute, and plug it back in. If your issue is solved now, celebrate
    If not solved, however, try and see if you have the same issue on another network.
    You can also change the DNS server you use to something like OpenDNS. There is a guide here, preferably set it up on your router, but if that's too technical, try setting it up on your Mac only: https://store.opendns.com/setup/?__utma=247635969.764677354.1418757510.141875751 0.1418757510.1&__utmb=247635969.3.10.1418757510&__utmc=247635969&__utmx=-&__utmz =247635969.1418757510.1.1.utmcsr=google|utmccn=%28organic%29|utmcmd=organic|utmc tr=%28not%20provided%29&__utmv=-&__utmk=7372593#/
    One last thing about changing DNS servers. Really, your internet provider should be more than capable of serving you pictures from Amazon and Facebook (by the way, most of these pics are not hosted by Amazon and Facebook really, but by an outside company called Akamai that a lot of large companies use. So I should probably be saying: "your ISP should not have any trouble serving content from Akamai's servers")
    Hence, the proper advise I should give you is: contact your ISP and ask them if they've been having DNS issues lately. Barring that: you can save yourself some helpdesk pain and use OpenDNS or Google DNS.

Maybe you are looking for

  • Calling a function in the select clause.

    I am using Oracle 11g. I am trying to write a query like this select name,age, sal, avg = avg_salary(age) from customer where sal >= avg; However, I am not able to do so. What the query is trying to do is print the name, age and salary of every custo

  • Transferring from old to new

    I currently have an iphone 3gs through tmobile but im getting an iphone 4 through verizon on september 10th, how do I transfer my apps, contacts and other information onto my new phone? thanks

  • EAP-Fast

    Hi, I have a AP1100 and a repeater AP1100. The AP acts as a Radius server and the clients (all AIR-350) use LEAP, WPA and TKIP. Everything works just fine. Now I want to secure my environment a bid more and make use of EAP-Fast. I can't get it work.

  • Why is my video having problems?

    There is really just two things that i am concerned with. 1. Every few seconds my video will start lagging, then i will pause it and play it again and it will be fine. 2. The regularly yellow line in the top of the editing box turned red on three cli

  • Drawing a sine curve in 3D

    I would like to draw a sine curve in Java 3D. Is there a way to do that? I am generating points on the fly and putting them in Point3D array. Then I generated the indices and used IndexedLineArray to draw lines on the fly. But they don't show up prop