images in jar file

Posted on 2006-05-04
Last Modified: 2010-03-31
i am loading images into the java file using the following code
ImageIcon icon = new ImageIcon(pics//example.gif)
this works when i compile it however when i export a jar file the pics dont seem to load up
Question by:isarasoo
    LVL 30

    Expert Comment

    >> ImageIcon icon = new ImageIcon(pics//example.gif)

    That won't compile. Do you have "pics/example.gif" or "/pics/example.gif" ? You don't need 2 // over there BTW. What is the hierarchy of the image in the JAR file?
    LVL 30

    Accepted Solution

    Try using:

    URL url = getClass ().getResource ( "pics/example.gif" ) ;
    ImageIcon icon = new ImageIcon ( url ) ;

    LVL 23

    Assisted Solution

    LVL 92

    Assisted Solution

    you also need to make sure you include the images in your jar

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    method argument as final 1 54
    factorial example challenge 10 45
    bunnyEars2 challenge 6 48
    base64 decode encode 12 55
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now