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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:08:44+00:00 2026-05-28T02:08:44+00:00

I have the following snippet that loads the images: String imgName = /assets/ +

  • 0

I have the following snippet that loads the images:

    String imgName = "/assets/" + name;
    URL imgURL = Groovy.class.getResource(imgName);
            System.out.println(imgURL.getPath());
    Toolkit tk = Toolkit.getDefaultToolkit();
    Image image = tk.getImage(imgURL);
    return image;

And where the image is drawn:

        Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
        g.setColor(Color.black);
        g.fillRect(0,0,screenWidth,screenHeight);
        g.drawImage(background, 0, 0, null);
        System.out.println(background.getWidth(null));
        if (background.getWidth(null) < 0)
            System.exit(1);

However imgURL always returns null. I’m using Eclipse (and fresh to it, blegh), and running the classes with run or debug option. If I change the path, it gives a file not found exception.

File structure is as followed:

Project -> src and assets -> src has Groovy, assets has image -> Groovy has Groovy.class

Edit: I switched back to Netbeans. The imgURL is now loading fine and getPath returns it’s correct path. However the image width / height return -1. This is the actual problem now.

Edit: -1 means that the width is not yet known, however displaying the image shows a white screen.

  • 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-28T02:08:45+00:00Added an answer on May 28, 2026 at 2:08 am

    The problem resided in the use the toolkit to get the image, possibly because I’m using OpenJDK? Anyway, using ImageIO.read(imgURL) fixed this.

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

Sidebar

Related Questions

I have following code snippet that i use to compile class at the run
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have following html snippet: <div class=rsw-pp rsw-pp-widget> <div g:type=AverageStarRating g:secondaryurls=http://maps.google.com/?cid=12948004443906002997 g:decorateusingsecondary=http://maps.google.com/?cid=12948004443906002997 g:groups=maps g:rating_override=2.998000
I have the following snippet of code that loops through the jQuery animate function
I have the following code snippet: $.getJSON(http://localhost:8080/images, function(data) { var items = []; $.each(data,
I have the following snippet that uses Joda time: import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormat; import
I have the following code snippet, which loads data from a CSV file into
If we have the following 2 snippets of code in c++ that do the
I have code that looks like the following: //unrelated code snipped resolver.reset(new tcp::resolver(iosvc)); tcp::resolver::query
I have a line of PHP code that does the following: $xml = <xml><request>...[snipped

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.