Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: images and ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 14 of 15 Topic 16051 of 16078
Post > Topic >>

Re: images and jar file craziness

by Redbeard <tom.cowdery@[EMAIL PROTECTED] > May 11, 2008 at 07:27 PM

On May 9, 3:48 am, Nigel Wade <n...@[EMAIL PROTECTED]
> wrote:
> Redbeard wrote:
> > On May 6, 11:02 pm, Roedy Green <see_webs...@[EMAIL PROTECTED]
>
> > wrote:
> >> On Tue, 6 May 2008 11:41:07 -0700 (PDT), cowde...@[EMAIL PROTECTED]
> >> wrote, quoted or indirectly quoted someone who said :
>
> >> >While I'm certainly no expert, I'm also not a novice.  I've written
> >> >several apps and gotten them to work in a jar, but none had images
in
> >> >them.  And I can get this app to run from the jar (depending on what
> >> >code I have used), but I can't get the images to work.
>
> >> I understood from you earlier post you could not get a jar to execute
> >> at all.  Apparently it executed but crapped out as soon as it came
> >> time to deal with the image.
> >> --
>
> >> Roedy Green Canadian Mind Products
> >> The Java Glossaryhttp://mindprod.com
>
> > Sorry for the confusion.  Apparently, I wasn't as clear as I thought I
> > was.
>
> > Before I posted, I had researched and tried a variety of different
> > ways to load the images.  They all worked from the class files, but
> > none would load the images once I jarred everything up.  Most of the
> > time the jar file would execute, but not have images.  However, SOME
> > techniques actually kept the jar file from executing - or more likely
> > - caused it to hang before anything became visible.
>
> > I was sure I was making some small mistake that I just couldn't see -
> > which is why I posted.  I see now that my problem was that I was using
> > the relative path rather than the absolute path.  Obviously, I have
> > more to learn about that.  I'd read about absolute vs. relative paths
> > and thought that relative was the way to go.
>
> It's not that you were using a relative path, relative paths are
perfectly ok
> and it may be argued that they are the preferred method. The problem is
most
> likely that you were using the wrong relative path. There is only one
absolute
> path, and that path is independent of the object you use as the basis of
the
> getClass().getResource(). There are a large number of relative paths you
might
> use, and each is dependent on where you base the relative path.
>
> For a relative path the origin is the directory containing the class
which is
> returned by getClass(). You need to base your relative path in
getResource()
> from that directory. Don't forget that the jar has a directory structure
based
> on the package structure of the class definitions.
>
> --
> Nigel Wade

In my case, I only had three files, so I hadn't bothered to create a
package.  I have used packages in other projects, but primarily when
creating libraries for use by others, not is a small project like
this.  My source code and compiled files all ended up in the same
folder (directory) G:\Javasource\MemoryGame and the images were in G:
\Javasource\MemoryGame\images.

Do you have to use packages to get a relative path to work?




 15 Posts in Topic:
images and jar file craziness
Redbeard <tom.cowdery@  2008-05-05 20:01:07 
Re: images and jar file craziness
Lew <lew@[EMAIL PROTEC  2008-05-05 23:45:53 
Re: images and jar file craziness
cowderyt@[EMAIL PROTECTED  2008-05-06 06:03:56 
Re: images and jar file craziness
Nigel Wade <nmw@[EMAIL  2008-05-06 15:26:45 
Re: images and jar file craziness
Roedy Green <see_websi  2008-05-06 16:35:16 
Re: images and jar file craziness
Roedy Green <see_websi  2008-05-06 16:33:15 
Re: images and jar file craziness
cowderyt@[EMAIL PROTECTED  2008-05-06 11:41:07 
Re: images and jar file craziness
Roedy Green <see_websi  2008-05-07 04:02:14 
Re: images and jar file craziness
cowderyt@[EMAIL PROTECTED  2008-05-06 11:54:47 
Re: images and jar file craziness
cowderyt@[EMAIL PROTECTED  2008-05-06 12:00:41 
Re: images and jar file craziness
Redbeard <tom.cowdery@  2008-05-07 18:54:36 
Re: images and jar file craziness
Roedy Green <see_websi  2008-05-08 18:23:56 
Re: images and jar file craziness
Nigel Wade <nmw@[EMAIL  2008-05-09 09:48:24 
Re: images and jar file craziness
Redbeard <tom.cowdery@  2008-05-11 19:27:53 
Re: images and jar file craziness
Lew <lew@[EMAIL PROTEC  2008-05-11 23:04:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 9:02:12 CDT 2008.