Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6716189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:42:12+00:00 2026-05-26T08:42:12+00:00

Problem is the following – I am writing a program with Eclipse in java..

  • 0

Problem is the following – I am writing a program with Eclipse in java..
The resulting folder structure is main project folder: Animal Classification/ inside of it: bin/ , images/, pics/ in the bin/ folder : users/metropolia/allClasses.class

Program starts normally and works -> images are in the folders images/ and pics/ -> they are used by users.metropolia.Hieararchy

But when I create a .jar out of it either through Eclipse or through CMD.exe -> in the folder different from the source folder the jar does not show images even though they are packed inside of it. Inside the Hierarchy.class the path to the images is (“images/name.jpg” or “pics/name.jpg”).

Then I tried to use the ClassLoader.getSystemResource(“images/name.jpg”) – but now the eclipse and the cmd.exe give warnings and dont start the program -> NullPointerException in thread main = mistake in the line where ClassLoader static is used…

I would really appreciate any help

Update:

http://users.metropolia.fi/~artemm/

Download the code from there plz
It can be downloaded as SFX-archive or if you are afraid of viruses just download usual RAR archive

I really appreciate your help

Main class is in users/metropolia/Program.java

Update 2:

@MockerTim

THank you very much for your help – now everything works. Moreover, I managed to find one more snag – it didnt call for the images, because the call was : “Fish.jpg” and the picture was : “fish.jpg” – no wonder it could not find anything and gave mistakes.

THank you very much once again, I really appreciate!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:42:12+00:00Added an answer on May 26, 2026 at 8:42 am

    You are using incorrect paths.

    You should use the following paths in your code:
    ../../images/name.jpg and ../../pics/name.jgp, respectively.

    As Nate mentioned, you can start you path with “/”, and use /images/name.jpg and /pics/name.jpg, respectively.

    When you use images/name.jpg path in the class users.metropolia.Hieararchy, your code tries to find file name.jpg in the folder users/metropolia/images. And, of course, it fails.

    See Locating resources in Java for details.

    Here is the simple example:

    package users.metropolia;
    
    import java.net.URL;
    import javax.swing.ImageIcon;
    
    public class IconManager {
        /** Returns an ImageIcon, or null if the path was invalid. */
        public static ImageIcon loadImageIcon(String path) {
            URL imgURL = IconManager.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                    return null;
            }
        }
    
        public static void main(String[] args) {
            // Using absolute (to jar) paths
            ImageIcon icon3 = loadImageIcon("/pics/spider.jpg");
            ImageIcon icon4 = loadImageIcon("/imagess/ant.jpg");
        }
    }
    

    Update:

    I’ve downloaded your code (from your link), and added the above IconManager class and used its loadImageIcon() method to initialize your anImages array and MyDrawPanel class.
    Now your progam looks like this:

    enter image description here

    The changes, that I’ve made to your code:

    In class Hierarchy:

    for (int i = 0; i < options.length; i++) {
      //anImages[i] = new ImageIcon("/images/" + options[i] + ".jpg");
        anImages[i] = IconManager.loadImageIcon("/images/" + options[i] + ".jpg");
        listObj[i] = new RendObject(options[i], anImages[i]);
    }
    

    In class MyDrawPanel:

    public MyDrawPanel(String x) {
      //picture = new ImageIcon(x).getImage();
        picture = IconManager.loadImageIcon(x).getImage();
    }
    

    And, of course, I removed “generic” from JComboBox where needed.

    Remark: To make your program show selected image instead of spider image, you should modify your program further.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following problem. I have typical master/detail UI scenario. I set main object
I have the following problem: I have a JTable inside a JScrollPane, and the
I have following problem: My program should decide at runtime to load an function
I encountered following problem: I write program in c++ using VS2010. Debug build works
My problem is following: I need to align text inside DateTimePicker component to center.
I have following problem to be solved in java: Implement class Alkio. Test with
I have following problem: have to model classes (posts and users). Main view is
I have following problem: I have a TabActivity which works well. Inside, there is
I have a problem following from my previous problem . I also have the
Following problem: I want to render a news stream of short messages based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.