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 16 of 16

Thread: Simple problem, please help!?!

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Simple problem, please help!?!

    Hello everyone. Cody here. I was wondering if anyone knew how to add images to a class without having to direct to the C drive? Like add it to the game like in Java development. I'm currently making a game and I'd like to know if anyone can help. I made a folder in my project called "imgs" and put my images in there. Next I did this, "ImageIcon i = new ImageIcon("@imgs/bg1.jpg");" Can someone tell me why this isn't working? Please? Thank you guys very much for your time. All help will be greatly appreciated. Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    why this isn't working?
    Most common reason is the program is looking in the wrong place for the files.
    Are the images in the folder where the program is looking for them?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!

    Heres a screenshot https://fbcdn-sphotos-h-a.akamaihd.n...a86a91d535af30 (Tell me if the link don't work)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    If you can't tell if the program is looking in the correct place for the images, you can see where the program is looking by creating a File object with the path to an image file and print out the value of the File object's absolute path.

    I don't follow links to files.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!


  6. #6
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!


  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    Did you print out the File object's path as I suggested? What printed? Was the path that printed where the image file is located?

    I don't know what that image is supposed to show. Can you explain?

    I'm done for tonight.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!

    That didn't make sense man. I created a new file in the images folder. That's all I understood

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    Did you print out the value of the File class's absolute path method to see where the program is looking for the image file?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!

    Quote Originally Posted by Norm View Post
    Did you print out the value of the File class's absolute path method to see where the program is looking for the image file?
    I didn't understand how you told me to do it

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    which part don't you understand?
    Create a File class object using the path to one of the image files
    Call the println() method to print the File object's absolute path
    Something like this:
    File fke = new File(<PATH TO IMAGE FILE HERE>);
    System.out.println("image's path="+fke.getTheMethodFromTheAPIdoc());
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!

    I don't see why this is necessary... when I could use the "@imgs/l1.png" but its not working. All the information you need should be in the pictures

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    but its not working
    Are you trying to get the program to work? The following is From post#2
    Most common reason is the program is looking in the wrong place for the files.
    Are the images in the folder where the program is looking for them?


    The code like that in post#11 will show you where the program is looking.

    Are the image files in the folder whose path is printed by the code from#11?
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Simple problem, please help!?!

    Quote Originally Posted by CodyMoorea View Post
    I don't see why this is necessary... when I could use the "@imgs/l1.png" but its not working. All the information you need should be in the pictures
    So instead of following Norm's advice on how to diagnose your problem you just want some magic to fix it.
    Improving the world one idiot at a time!

  15. #15
    Junior Member
    Join Date
    Apr 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Simple problem, please help!?!

    Quote Originally Posted by Junky View Post
    So instead of following Norm's advice on how to diagnose your problem you just want some magic to fix it.
    What? No, the way I want to do it shouldn't involve all of these steps. When I developed for Android, these were not necessary. I was wondering if it's different for game developing.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Simple problem, please help!?!

    Does your program find the files now?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Simple problem help!
    By spunkyk014 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 14th, 2013, 07:01 PM
  2. hello! can i please get some help with a simple loop problem?
    By zerocool18 in forum Loops & Control Statements
    Replies: 6
    Last Post: October 13th, 2012, 10:31 AM
  3. please help, simple problem
    By grandmst in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 13th, 2011, 06:26 PM
  4. Very simple problem...PLEASE HELP!
    By dungeondragon in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 1st, 2011, 07:19 AM
  5. Simple problem...
    By _lithium_ in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 6th, 2011, 12:02 AM

Tags for this Thread