Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Image loads in IDE but not when exported || creating reffered libary problem

  1. #1
    Member
    Join Date
    Jan 2013
    Posts
    39
    My Mood
    Relaxed
    Thanks
    1
    Thanked 1 Time in 1 Post

    Exclamation Image loads in IDE but not when exported || creating reffered libary problem

    So i am making a basic game and i am loading the images as such :
    try {
    			background = ImageIO.read(new File(res/textures/bg.jpg"));
    			buildingManager.getButton().setCupcake_normal(ImageIO.read(new File("res/textures/cupcake normal.png")));
    			buildingManager.getButton().setCupcake_clicked(ImageIO.read(new File("res/textures/cupcake clicked.png")));
    		} catch (IOException e) {
    			e.printStackTrace();
    		}

    Alot of sites say i have to add the folder where the folders are in as an class folder. So i did that but i dont get the same icon with the folder. i get this instead : code.PNG

    Also i see the images inside the exported jar but they cant be reached, how do i fix this?
    Last edited by The_pizzaguy; May 6th, 2014 at 07:17 AM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Image loads in IDE but not when exported || creating reffered libary problem

    Look into getClass.getResource(). Absolute or relative paths to files in your development environment aren't going to work when the project is moved to a .jar file.

  3. #3
    Member
    Join Date
    Jan 2013
    Posts
    39
    My Mood
    Relaxed
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Image loads in IDE but not when exported || creating reffered libary problem

    Well I'll dive into that i guess.

    --- Update ---

    Do you have a good link as for an explantion of how getClass().getResource(). is meant to be used?

    --- Update ---

    Okay figured it out, thanks for the hint.

Similar Threads

  1. Replies: 3
    Last Post: May 25th, 2014, 11:33 AM
  2. Creating weblogic server in Eclipse IDE
    By Javacrazy in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 24th, 2013, 12:58 PM
  3. IDE Eclipse Exporting Problem
    By DanielJamesCollier in forum Java IDEs
    Replies: 2
    Last Post: January 2nd, 2013, 06:26 PM
  4. Program Runs in Eclipse but Not When Exported
    By Pantheon8 in forum Java IDEs
    Replies: 2
    Last Post: August 17th, 2011, 05:57 PM

Tags for this Thread