Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Pls make my eclipse to look for images
Pls make my eclipse to look for images [message #20874] Tue, 13 May 2003 11:21 Go to next message
Eclipse UserFriend
Originally posted by: appzworm.hotmail.com

Hi all,

I am just experimenting with eclipse. I developed a simple JFrame using
eclipse and my project structure is like this

MyProject
|-src
|-mypackage.ui
|-MainFrame.java
|-images
|-doc

Now i have put the frmae icon and other label image files under /images
folder and I access the images thru the URL object
getClass().getClassLoader().getresource("images/file1.gif");

But when I run the program I am getting a NullPointerException and the
program just exits. But I exported the same project into a jar file with a
manifest with the full mainclass name(myackage.ui.MainFrame). When I run
this jar file, voila, it simple runs wothout any problem. Pls help me in
correcting the mistake which I am overlooking somewhere. Thanks a lot
friends
Re: Pls make my eclipse to look for images [message #21360 is a reply to message #20874] Tue, 13 May 2003 13:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

appzworm wrote:

> Hi all,

> I am just experimenting with eclipse. I developed a simple JFrame using
> eclipse and my project structure is like this

> MyProject
> |-src
> |-mypackage.ui
> |-MainFrame.java
> |-images
> |-doc

> Now i have put the frmae icon and other label image files under /images
> folder and I access the images thru the URL object
> getClass().getClassLoader().getresource("images/file1.gif");

> But when I run the program I am getting a NullPointerException and the
> program just exits. But I exported the same project into a jar file with a
> manifest with the full mainclass name(myackage.ui.MainFrame). When I run
> this jar file, voila, it simple runs wothout any problem. Pls help me in
> correcting the mistake which I am overlooking somewhere. Thanks a lot
> friends



You need to get the images directory on the classpath. In Eclipse 2.1,
you can add it as a Class Folder on the Properties->Java Build
Path->Libraries tab
Re: Pls make my eclipse to look for images [message #21390 is a reply to message #21360] Tue, 13 May 2003 14:23 Go to previous messageGo to next message
Eclipse UserFriend
But you need to put images under another directory too. That is because
if you made "images" a class folder, you can't access it using
"images/xyz.gif", you would need to use just "xyz.gif". This is because
the "images" directory becomes a root in the classpath.

Rich
Re: Pls make my eclipse to look for images [message #22251 is a reply to message #21390] Wed, 14 May 2003 09:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: appzworm.hotmail.com

Richard L. Kulp wrote:

> But you need to put images under another directory too. That is because
> if you made "images" a class folder, you can't access it using
> "images/xyz.gif", you would need to use just "xyz.gif". This is because
> the "images" directory becomes a root in the classpath.

> Rich

Thanks. Its working now. But can you please explain me the classpath
mechanism in eclipse, which led to this anomaly? Is there anyway I can use
the images folder as such rather than putting it under another folder and
adding that to the buildpath? Now why the jar file created was working
without any hitch in the first instance? TIA
Re: Pls make my eclipse to look for images [message #22920 is a reply to message #22251] Wed, 14 May 2003 14:58 Go to previous message
Eclipse UserFriend
Because when you created the jar file, you were running outside of
eclipse, and so you created your own classpath. When you exported into
the jar, did you in addition copy the images directory into the jar?

If you did, then you essentially added the images directory to the
classpath.

Look in the help for Eclipse under Java Development User Guide->Getting
Started->Project Configuration Tuturial
Previous Topic:Starting program from eclipse
Next Topic:jsp editor
Goto Forum:
  


Current Time: Thu Dec 26 22:57:56 GMT 2024

Powered by FUDForum. Page generated in 0.03274 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top