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 6931185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:40+00:00 2026-05-27T11:32:40+00:00

I think I’m suffering from some classpath blues here. I’ve been following the examples

  • 0

I think I’m suffering from some classpath blues here. I’ve been following the examples. I read the tutorials. But nothing seems to be working for me.

Let’s say I have a JPEG at the following URI: C:\Users\MyUser\someIcon.jpeg

And let’s say I have a Swing app that has a JPanel, and I want to add this JPEG into the JPanel (positioning/layout doesn’t matter).

How would SO accomplish this? I’m not getting any errors or exceptions, just not seeing the JPEG load. The code I’m trying to use is this:

String someIconUri = "C:\Users\MyUser\someIcon.jpeg";
URL imageUrl = getClass().getResource(someIconUri);
ImageIcon imageIcon = new ImageIcon(imageUrl);
myPanel.add(imageIcon);

Please advise…I’ve been dealing with this since noon today…and its midnight. Thanks in advance for any nudges in the right direction.

  • 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-27T11:32:41+00:00Added an answer on May 27, 2026 at 11:32 am
    String someIconUri = "C:\Users\MyUser\someIcon.jpeg";
    

    No it is not ‘some icon URI’, it is not a valid URI at all. Come to think of it, it is not even a compilable statement, since the String contains illegal escape chars!

    It might be something along the lines of..

    String someIconUri = "file:///C:/Users/MyUser/someIcon.jpeg";
    

    But then getResource() is neither needed or useful, since it will only locate resources on the run-time class-path. Just construct an URL directly from the String.


    But that is really only ‘part of an answer’. Here’s why.

    In this context, there are basically two types of resources. Application resources and (for want of a better word) User resources.

    Application resources.

    These resources might consist of things like frame icons, button and menu icons (Action icons), icons for tabs. Help files (and associated images), splash images..

    They should be added to a separate Jar (most often) and added to the run-time class-path of the application (either using the manifest or other means like applet element or JNLP file).

    Application resources should be accessed by URL, which can be obtained using getResource():

    URL iconUrl = this.getClass().getResource("/icons/copy.jpg");
    

    User resources.

    The user wants to open (edit/print) an existing text document, make an animated GIF from image frames, edit an image on their file system..

    For these types of resources (and presuming the app. is trusted or has no security manager), offer the user a JFileChooser. It will return a specific, existing File or more (depending on how configured and used).

    In that case, never convert the File to anything else, just use the instance(s) directly.


    Most methods that take input from resources (worth mentioning), will accept a File URL or InputStream.

    The last is useful for something generated in memory, or obtained from sources such as sockets or a JNLP API FileContents object. The latter is of special interest to sand-boxed apps. launched or embedded using Java Web Start.

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

Sidebar

Related Questions

I think it will be very hard for you to read the code but
I think this has probably been asked, but after reading a lot, I'm not
I think, the following can't be done in Java. But I would be happy
Think about the following: Your ISP offers you a dynamic ip-address (for example 123.123.123.123).
I think most people here understand the importance of fully automated builds. The problem
I think this is specific to IE 6.0 but... In JavaScript I add a
I think I know how to handle this case, but I just want to
Think of the following code: static int Main() { byte[] data = File.ReadAllBytes(anyfile); SomeMethod(data);
I think that asking this might be kind of silly but I'm still wondering
Think of the following services on one box: SOCKS proxy HTTP proxy SSH service

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.