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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:12:12+00:00 2026-06-15T10:12:12+00:00

I made a /header folder in the web pages directory in Netbeans and added

  • 0

I made a /header folder in the web pages directory in Netbeans and added an image named header.png. Now I want to access this image file in a servlet using the following code:

BufferedImage image = ImageIO.read(getClass().getResource(" /header/header.png"));

But this is not happening, it gives the following error:

java.lang.IllegalArgumentException: input == null!

Below is my project’s directory structure:

enter image description here

How is this error caused and how can I solve it?

  • 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-15T10:12:13+00:00Added an answer on June 15, 2026 at 10:12 am

    The Class#getResource() returns an resource from the class path, not from the public web content.

    You need ServletContext#getResource(), or better, getResourceAsStream() instead.

    BufferedImage image = ImageIO.read(getServletContext().getResourceAsStream("/header/header.png"));
    

    (note that I removed the trailing space from the path as well)

    Note that some users may suggest you to use ServletContext#getRealPath(), but you shouldn’t use it in this particular case as that may return null when the container is configured to expand the deployed WAR into memory instead of local disk file system.

    See also:

    • What does servletcontext.getRealPath("/") mean and when should I use it
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a header image, but for some reason I can't get it to
I've successfully made JQuery work with Master Pages, but not JQuery UI.My header in
I've had a folder in my repository. Then I have made this folder a
I made an custom UITableView. Then I made a custom header for sections. It
I have made a design with a fixed header and footer, with a liquid
I have made a rediculasly small snippet to make a sub-header stick to the
I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header.
I basically made a listview with Alphabet-Indexed section headers by following this tutorial. I'm
Made this nice little loop for hiding and showing div's, works as a charm
I am working on a website. I have made the header and the footer

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.