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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:01:29+00:00 2026-05-19T03:01:29+00:00

I am currently writing a program that I need to send to a friend

  • 0

I am currently writing a program that I need to send to a friend as a jar. The program has images that need to be loaded for the program to work properly and I want it all to be contained in the one jar. Currently it doesn’t work from the executable jar or when I run it through command line. It works in netbeans however.

Here’s the code I’m using:

To load the image I’m using:

protected ImageIcon createImageIcon(String path, String description)
{
 java.net.URL imgURL = getClass().getClassLoader().getResource(path);
 if (imgURL != null)
 {
     return new ImageIcon(Toolkit.getDefaultToolkit()
                  .getImage(imgURL),description);
 }
 else
 {
     System.err.println("Couldn't find file: " + path);
     return null;
 }
}

for the URL I’ve also tried just

 getClass().getResource(path)

The line where the image is supposed to be created is:

this.img =createImageIcon(File.separator+"."+File.separator
           +"resources"+File.separator+"tiles"+File.separator+"tile.png","tile");

My jar file is setup with the folder containing the class files and the resource folder both on the top level of it.

I have searched around for ways to resolve this, but I cannot find anything that works.

Thanks.

  • 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-19T03:01:29+00:00Added an answer on May 19, 2026 at 3:01 am

    Your URL will evaluate to "/./resources/tiles/tile.png" which does not make sense (but maybe the ClassLoader that is used when you run from NetBeans tolerates the error.)
    Try dropping the initial "/./". Also you do not need the references to File.separator as the string is treated as a relative URL and the forward slash is always valid.

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

Sidebar

Related Questions

I am currently writing a program which takes user input and creates rows of
I am currently writing a non-web program using mostly python and have gotten to
I am writing an iphone (IOS 4) program that capture live video from the
I'm currently re-writing a Vb6 program relying on ADO into C# w/ ADO.NET. I've
I am writing a little program in C# that scans a folder and opens
I am writing a program in Fortran and I need a way of calculating
I'm writing an autograder web application that accepts a program from the user as
I'm currently in a class on systems software development. We are writing the two-pass
I am writing a global hook DLL that needs to do some drawing using
The Problem: Background Information I'm writing an application for a client that is to

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.