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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:29:10+00:00 2026-05-13T09:29:10+00:00

I have added an image for my button,but when I run that frame this

  • 0

I have added an image for my button,but when I run that frame this exception will be thrown .why?please help me.

init:

deps-jar:
compile-single:
run-single:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.ImageIcon.<init>(ImageIcon.java:138)
        at ClientGUI.IdAndPasswordFrame.initComponents(IdAndPasswordFrame.java:91)
        at ClientGUI.IdAndPasswordFrame.<init>(IdAndPasswordFrame.java:22)
        at ClientGUI.IdAndPasswordFrame$4.run(IdAndPasswordFrame.java:200)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
BUILD SUCCESSFUL (total time: 1 second)

line 138:

public ImageIcon (URL location) {
    this(location, location.toExternalForm());
}

line91:

 jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/yahoo_1.gif"))); // NOI18N

I use this poor checking (Peter Lang recommended)which is:System.out.println(getClass().getResource(“/Images/yahoo_1.gif”)); and it returns null,why? please help me.

  • 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-13T09:29:10+00:00Added an answer on May 13, 2026 at 9:29 am

    This means, that getClass().getResource("/Images/yahoo_1.gif") returns null.

    JavaDoc states that this happens if

    the resource could not be found or the invoker doesn’t have adequate privileges to get the resource.

    1. Check if getResource really returns null:
      System.out.println(getClass().getResource("/Images/yahoo_1.gif"));

    2. Make sure that your path is correct and that it is in your classpath.

    EDIT:

    I just tried it with NetBeans. I created the following structure

    Source Packages
      Images
        yahoo_1.gif
    

    and your code worked fine. Is this your structure?

    Try to right-click on your application and select Clean and Build.

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

Sidebar

Related Questions

I got this issue with displaying a image that i allready have added as
I have wordpress site, i added like button for share post. But, i don't
I have this button which i have added a custom icon to. I would
See the below image. I have added a reset button at the end of
I have added multiple image upload to my site using HTML api's. I have
I have added an image to my form's resource file, myForm.resx, and I would
I have a DataTemplate containing an Image. To the Image I added a ContextMenu
I have a custom list, and I've added a 'Page Image' field by clicking
I have an image which is added to the project. In the simulator it
I have an image editing application, and I have custom adorners which get added

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.