Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Images in .jar file

  • 13-12-2006 5:29pm
    #1
    Closed Accounts Posts: 49


    Hey guys,

    Just wondering how to put images into a jar file. i keep getting an exception when i go to run it..

    cheers


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    What's the exception?


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Try using

    this.getClass().getClassLoader().getResourceAsStream( "x/y.z" );

    to load the images. If that doesn't work try posting some code and the exception (nearly always a good idea, btw - programmers are smart, not psychic).


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Heh. Smart, not psychic :)

    I've added that to the 'How to ask a question' sticky.


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    /curtsey :)


  • Closed Accounts Posts: 49 boyracer87


    Heres the exception:

    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(Unknown Source)
    at RaysZork.<init>(RaysZork.java:53)
    at RaysZork.main(RaysZork.java:69)


    I this right?:
    ImageIcon roompic1 = new ImageIcon(this.getClass().getClassLoader().getResourceAsStream("rooms1.gif"));
    


  • Advertisement
  • Closed Accounts Posts: 150 ✭✭Vuk


    ImageIcon roompic1 = new ImageIcon(this.getClass().getResource("rooms1.gif"));
    

    This should work!
    Good luck with ZorkUL(unless I'm wrong!)


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    The resource is returned relative to the root of the JAR, so if there are any folders in the JAR you have to specify them all.

    EDIT: Vuk's is more correct, sorry. The method I gave you returned an ImputStream.


  • Closed Accounts Posts: 49 boyracer87


    No...still doesent work..im getting the same exception when i try to run it...

    Vuk wrote:
    Good luck with ZorkUL(unless I'm wrong!)


    Howd you know that :eek: :confused:


  • Closed Accounts Posts: 150 ✭✭Vuk


    boyracer87 wrote:
    No...still doesent work..im getting the same exception when i try to run it...

    Howd you know that :eek: :confused:

    Hmmm as aidan was saying, have you got the images in a sub directory perhaps?
    Or maybe the images themselves are not being added to the jar file?
    I'm assuming that you have succesfully loaded the images previously with an IDE or command line build!

    Oh and as for how I know, I'm sitting here, working away on the same project, with nothing but the hum of my computer, 20 Benson and a load of coffee for company...


  • Closed Accounts Posts: 49 boyracer87


    Vuk wrote:

    I'm assuming that you have succesfully loaded the images previously with an IDE or command line build!

    NO.....:o :o:o .Howd ya do that??
    Vuk wrote:

    Oh and as for how I know, I'm sitting here, working away on the same project, with nothing but the hum of my computer, 20 Benson and a load of coffee for company...

    Who are ya????


  • Advertisement
  • Closed Accounts Posts: 150 ✭✭Vuk


    @boyracer87, check your PMs!
    We can try to work it out from there


  • Closed Accounts Posts: 49 boyracer87


    Vuk...check PM's


Advertisement