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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:40:08+00:00 2026-06-04T12:40:08+00:00

First I used JLabel and ImageIcon. It worked fine. However, the image doesn’t show

  • 0

First I used JLabel and ImageIcon. It worked fine. However, the image doesn’t show up when I exported it to JAR.
So, then I created my own ImagePanel and used the drawImage method to display it.
But it terminates and throws an

exception in thread “main” java.lang.IllegalArgumentException: input
== null!

well, my code follows below..

startMenu

public class startMenu extends JFrame{
  ...
  URL imgUrl = getClass().getResource("images/contacts.png");

  public startMenu(){
    ...
    ImagePanel imgPanel = new ImagePanel(imgUrl);
  }

}

ImagePanel

public class ImagePanel extends JPanel{

    private Image image;
    private URL imgUrl;

 public ImagePanel(URL url){
        this.imgUrl= url;

        try{    
            image = ImageIO.read(imgUrl);
        } 
        catch (IOException e) {
            System.out.println("no such file");
        }
    }

 @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if(image!=null){
             g.drawImage(image, 10, 12, 128, 128, this);
        }
        else{
            g.drawImage(image, 0, 0, this);
        }
    }

    @Override
    public Dimension getPreferredSize() {
       return new Dimension(150,150);
    }
}

If I would use ImageIcon with an imageUrl. It shows the same error message.

  URL imgUrl = getClass().getResource("images/contacts.png");
    private ImageIcon adBook = new ImageIcon(imgUrl);
    private JLabel mainImg = new JLabel(adBook);
  • 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-06-04T12:40:09+00:00Added an answer on June 4, 2026 at 12:40 pm

    problem is where the Images are located. I always saved the images directly inside the directory where “src” and “bin” are. “but getClass().getResource(“…”)” returns the path of bin. So I just had to move the image folder into “src” , so it will automatically make a copy of this directory into ‘bin’. problem solved.

    URL imgUrl = getClass().getResource("images/contacts.png");
    

    returns–> Q:\workspace\project name\bin\images\contacts.png

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

Sidebar

Related Questions

I used cURL to authenticate first then login via POST to a cms. Then
This is the first time I've used a 3rd party jar, but it seems
The problem is as follows: first I used the DownloadFile function with the show
I am trying to create input text like below Image : First I used
I created a github new repository first in github webpage and then I opened
History: I read from one of Knuth's algorithm book that first computers used the
I struggle to uninstall VS 2010. I downloaded and used first trial version for
I'm trying to create an application that uses c2dm service. So. First I used
Least Recently Used (LRU) Cache is to discard the least recently used items first
Yesterday I used jQuery UI for the first time and I think I'm going

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.