Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32
  1. #21
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Either that, or as I have been hinting at, the variable only contains the name of the image and not the complete path.
    ok so in Netbeans the project folder is Clash20
    the directory in for this all is

    Clash20 -
    -----build
    -----dist-
    ----------Clash20.jar-
    --------------META-INF
    --------------clash20-
    --------------------testgame-
    --------------Main.class
    -----src-
    ----------clash20-
    ------------testgame-
    ------------Main.java
    Anyways, in the IDE my program runs like i said from before using the getClass().getResourceAsStream(imageFile);
    but as usual, when the Jar runs the stream comes back null, meaning it couldnt find the file.

  2. #22
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Either that, or as I have been hinting at, the variable only contains the name of the image and not the complete path.
    Its working now... :confused: I placed all the resources in the same directory as the main class file. It seems to work just fine now. I have no idea why though. im so confused why it couldnt find the directory. so weird. but it works now. finally.

  3. #23
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Quote Originally Posted by rdjava View Post
    nope, its there, i opened the jar with winzip. the path is correct and the image does exist
    Ok, let's try using the classloader directly and see if that does anything differently.

    Java Code:
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    
    BufferedImage im = ImageIO.read(cl.getResourceAsStream("....relative path to image file in your jar"));
    Keep in mind that ImagIO does not work with every image type. If you stick to just jpegs and png's you should be ok.

    When you decompressed the jar file (using jar xf as suggested previously), what was the exact path it reported for your image file? That's the path you must use, including foward slashes rather than backslashes. If you're on windows, you still have to use unix style paths when extracting from a jar file.

  4. #24
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    The do a println() with the variable in it.
    In other words do some debugging.

  5. #25
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    Ok, let's try using the classloader directly and see if that does anything differently.

    Java Code:
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    
    BufferedImage im = ImageIO.read(cl.getResourceAsStream("....relative path to image file in your jar"));
    Keep in mind that ImagIO does not work with every image type. If you stick to just jpegs and png's you should be ok.

    When you decompressed the jar file (using jar xf as suggested previously), what was the exact path it reported for your image file? That's the path you must use, including foward slashes rather than backslashes. If you're on windows, you still have to use unix style paths when extracting from a jar file.
    actually the whole issue was when you are loading an image from lets say "Image/image.bmp" and you use

    imageFile = "Image/image.bmp";
    InputStream is = getClass().getResourceAsStream(imageFile);
    image = ImageIO.read(is);

    apparently its ALL case sensitive, if you use image/image.bmp it wont find it, which is really weird, i never thought it would be case sensitive, but for some reason it is, so my whole problem has been solved. I knew something was not right, i had everything, and i knew that this simple task was not that hard, the only thing is you HAVE to specify exactly what the names are, if the folder is "Images" you have to write it as it is. "Images" not "images" or "IMAGES"

  6. #26
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Since when has java not been case sensitive? On Windows, when referring to files, you can sometimes get away with it, but that is a property of the Windows Filesystem. When those things then go into a jarfile you can't "get away with it" anymore as the entries in a jarfile are, of course, also case-sensitive. Just assume everything is case sensitive and you'll be okay.

  7. #27
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Since when has java not been case sensitive? On Windows, when referring to files, you can sometimes get away with it, but that is a property of the Windows Filesystem. When those things then go into a jarfile you can't "get away with it" anymore as the entries in a jarfile are, of course, also case-sensitive. Just assume everything is case sensitive and you'll be okay.
    k well why wasnt anyone pointing that out? I had to figure that out on my own. I've always been able to get away with non-case sensitive calls with file IO.

  8. #28
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by rdjava View Post
    k well why wasnt anyone pointing that out? I had to figure that out on my own. I've always been able to get away with non-case sensitive calls with file IO.
    Seriously. How was anyone to know that this was your main problem? Please understand that you post a question here with a huge amount of knowledge about your problem that we can only tease out a bit at a time. I think that your expectations about our abilities (all too human) needs to be reset.

  9. #29
    rdjava's Avatar
    rdjava is offline Member
    Join Date
    Jan 2011
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Seriously. How was anyone to know that this was your main problem? Please understand that you post a question here with a huge amount of knowledge about your problem that we can only tease out a bit at a time. I think that your expectations about our abilities (all too human) needs to be reset.
    well then we are all just the blind leading the blind hoping one of us will see the light. My expectations are high due to im posting in advanced java. besides my problem has been solved case closed.

  10. #30
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by rdjava View Post
    well then we are all just the blind leading the blind hoping one of us will see the light. My expectations are high due to im posting in advanced java. besides my problem has been solved case closed.
    Your misguided expectations have nothing to do with this being in the advanced Java section and all to do with your not giving enough information for others to be able to guess your problem and its solution in the first place. And the case is not closed since you started this argument. Lord help me Jebus.

  11. #31
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by rdjava View Post
    well then we are all just the blind leading the blind hoping one of us will see the light. My expectations are high due to im posting in advanced java. besides my problem has been solved case closed.
    Well, because you told us the images where in a directory named "images" when they were really in a directory named "Images". How were we to know that? Through osmosis?

  12. #32
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,925
    Rep Power
    19

    Default

    How many times had we asked what the full value of imageFile was, and what the full path to the file was?

    This is what copy/paste and debugging code is for so we can see the actual values, not what people think the values are.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Array, I/O with a .txt file problems
    By basketball8533 in forum New To Java
    Replies: 4
    Last Post: 10-28-2010, 09:49 AM
  2. problems with txt file
    By blumdiggity in forum New To Java
    Replies: 1
    Last Post: 02-27-2010, 01:16 PM
  3. Jar file problems!
    By viper81 in forum Eclipse
    Replies: 3
    Last Post: 12-31-2008, 10:50 AM
  4. Problems with file dir
    By willemjav in forum Java Applets
    Replies: 0
    Last Post: 02-07-2008, 12:08 AM
  5. problems with the name of file
    By bbq in forum Java Servlet
    Replies: 0
    Last Post: 06-28-2007, 04:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •