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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:50:44+00:00 2026-06-16T13:50:44+00:00

For some reason the following code is not importing the image correctly and displaying

  • 0

For some reason the following code is not importing the image correctly and displaying it. If I comment out the draw part it work. I can not figure out why.

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class BoardBuild extends JPanel{
    String picPath = "pictures/";
    String[] fileName = {"board.png"};
    ClassLoader cl = BoardBuild.class.getClassLoader();
    URL imgURL[] = new URL[1];
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image imgBG;
    public BoardBuild() throws Exception {
        for (int x = 0; x < 1; x++)
            imgURL[x] = cl.getResource(picPath + fileName[x]);
        imgBG = tk.createImage(imgURL[0]);
    }
    public void paintComponent(Graphics g) {
        g.drawImage(imgBG, 0, 0, 150,150 , 0, 0,73, 73, this);
    }
}

As it is Eclipse, the pictures are in the folder workspace\BoardMaskTest\src\pictures.
I would appreciate the help.

  • 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-16T13:50:45+00:00Added an answer on June 16, 2026 at 1:50 pm

    Resources are taken from from the class path, looking with 7zip or Winzip in the jar one sees:

    String picPath = "/pictures/";
    

    Furthermore the image can be loaded as

        for (int x = 0; x < 1; x++)
            URL url = getClass(().getResource(picPath + fileName[x]);
            imgBG = ImageIO.read(url);
            InputStream in = getClass(().getResourceAsStream(picPath + fileName[x]);
            imgBG = ImageIO.read(in);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason the following code does not work as expected when in IE
For some reason, the following code will work: The following code does not work:
For some reason, the following code does not work: char cValue = '8'; int
For some reason the following code doesn't work on Windows XP. new URL(file:// +
I'm new to Javascript and for some reason I can't get the following code
In my jquery i have the following code, which for some reason is not
For some reason, the following code doesn't work: var users = window.SQLitePlugin.openDatabase(users,1.0,Demo,-1); users.transaction(function(tx){ KovarApp.lib.say(Transaction
For some reason the following code doesn't work. var a1 = Math.floor(Math.random()*4+1); //Answer2 for(a2
I'm not sure why, but for some reason, the following code skips the else
For some reason I can receive email with the following code at yahoo.com, but

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.