🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9541

Re: Problem with setIcon in JButton

#9541
From: John P. McGrath
Date: Sat, 11 Mar 2000 00:00
31 lines
1343 bytes
On 10 Mar 2000 01:46:06 -0800, Carlos wrote:

> At runtime (java.exe) , executing the line:
> 
>   jButton1.setIcon(new ImageIcon(
>       srvReports.MarcoVis.class.getResource("exit.gif")));
> 
> this exception occurs:  
> 
> java.lang.NullPointerException

The getResource() call is returning null, since it cannot find the 
resource.  To deal with that, you should probably use something like 
this:

    URL url = srvReports.MarcoVis.class.getResource("exit.gif");
    if ( url != null ) {
        jButton1.setIcon( new ImageIcon(url) );
    }

> This image ("exit.gif") is already added to the project (srvReports),
> and it is distributed in the jar file.
> "Exit.gif" is located in the project folder too.

It should be stored in the same directory as the .class file for the 
class that loads it.

-- 
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.1333a1cb3a279cb89897eb@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38c8c45e@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,6e45252150779fb9
X-Google-Attributes: gid111d45,public
From: John P. McGrath <JPMcGrath@fast.net>
Subject: Re: Problem with setIcon in JButton
Date: 2000/03/11
Message-ID: <MPG.1333a1cb3a279cb89897eb@forums.borland.com>
X-Deja-AN: 595969740
References: <38c8c45e@dnews>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing