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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:38:27+00:00 2026-06-04T08:38:27+00:00

The image path is all correct only, I don’t know why this error is

  • 0

The image path is all correct only, I don’t know why this error is coming.
Any one have any idea?

Code is for putting a background image in a frame and add button over that image

The error is

Uncaught error fetching image:
    java.lang.NullPointerException
        at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:99)
        at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:113)
        at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:240)
        at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
        at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)

Code

Error is coming while running the code :

        public class BackgroundImg extends JPanel {

            private Image img;

          public BackgroundImg (String img)
          {
              this(new ImageIcon(img).getImage());
          }

          public BackgroundImg (Image img)
          {
            this.img = img;
            Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
            setPreferredSize(size);
            setMinimumSize(size);
            setMaximumSize(size);
            setSize(size);
            //setLayout(null);
          }

            @Override
          public void paintComponent(Graphics g)
            {
                super.paintComponent(g);
            g.drawImage(img, 0, 0, null);
          }
        }

        public class ApplicationFrame {

        public static void main(String[] args) throws ImageAccessException {
        BackgroundImg panel = new BackgroundImg(Toolkit.getDefaultToolkit().createImage(ApplicationFrame.class.getResource("C:\\test.png")));
    JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(800, 600);

                frame.getContentPane().add(panel);
                ApplicationContents.addContentsToPane(panel);

                frame.setVisible(true);
                //   frame.setVisible(true);

            }

        }


    }
public class ApplicationContents {
    public static void addContentsToPane(Container pane)
    {
        //pane.setLayout(null);
        pane.setLayout(new FlowLayout());

        JButton b1 = new JButton("Test");

        pane.add(b1);

        //Insets insets = pane.getInsets();
        //Dimension size = new Dimension(120,32);

        // b1.setBounds(0 + insets.left, 0 + insets.top,
         //            size.width, size.height);


         b1.addActionListener(
                 new ActionListener()
         {
             public void actionPerformed(ActionEvent event)
            {

                 JOptionPane.showMessageDialog(null, "Test" , "Test", JOptionPane.ERROR_MESSAGE);
            }
         }
         );
    }

}
  • 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-04T08:38:31+00:00Added an answer on June 4, 2026 at 8:38 am

    getResource() loads a resource from classpath, not an OS path, so even if “C:\test.png” would be correct you cannot load it that way.

    Also, please check the return value of getResource() before using it so you’d catch these kinds of errors.

    You might want to bundle the image as a resource within your jar and load it using path that specifies the location within your jar.

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

Sidebar

Related Questions

I have images placed in following path res>drawable>Images>Currencies>[All images] I have made a custom
Save one image path in the database... and whenever a call is made to
I just started learning Flex this week, and I cannot get an image path
I have to find the next image, based on the current image path. It's
Im unable to find out the correct path for inclusion of my Carrierwave image.
I have found a PHP project that wraps all the main command line image
Given an original image of: This resizes to look as such: ALL the images
I'd like to know if this code... echo $this->Html->link( <h3>test</h3>.$this->Html->image(image.jpg).<p>Some text</p>, /link, array('escape' =>
When using GetModuleFileNameEx to query the image path of a running process, some processes
I am using jquery for changing image path but its not working for asp.net

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.