×

Discussion Board

Results 1 to 11 of 11

Thread: Image path

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Image path

    Could any one explain the path I need to use with Image.createImage("/test.png");
    Where do I put the image on the computer for use with the emulator and where do I store it on the phone?

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Image path

    You put it in the JAR file. The JAR file is basically a ZIP file. Check your IDE's documentation for how to add resource files to the JAR.

    Graham.

  3. #3
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: Image path

    Question:
    what IDE are you using?
    Netbeans,
    Eclipse

    ?
    :Ruben

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Re: Image path

    Eclipse, I must be real thick not found it in the doucmenatation yet!

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Image path

    If your project got created with a "res" folder, then put them there.

    Are you using the Eclipse MTJ (Mobile Tools for Java)?

    Graham.

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Re: Image path

    I have copied the image into the res directory do I need to do anything else?

    When I use:

    Image Logo = Image.createImage("/test.png");
    //ImageItem(label,Image,layout,alternative text)
    ImageItem imageitem = new ImageItem("ImageItem Example", Logo, ImageItem.LAYOUT_CENTER,"");
    StartScreen.append(imageitem);

    I get the message:

    Exception occurred: java.io.IOException: Cannot read /test.png

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Image path

    The code looks correct... assuming the file is in the right place!

    Points to note:

    1. You are right to put the leading "/". Filenames must start with a "/".

    2. The name must match exactly. Strictly, implementations are case sensitive, so "/test.png" will not match "/Test.png". However, some implementations are insensitive, which results in code that works on some devices, but breaks on others. Do as you have done, and keep all resource file names all lower case. (Not source file names, they should follow the convention for class names.)

    I suggest you build a JAR, and look inside it. You can use the command-line JAR tool (from the JDK) for this.

    Code:
    jar tvf myapplication.jar
    Or, open it with something like WinZIP (JAR files are just ZIP files).

    Check that "test.png" is in there, and check what path it's in. It could be missing, or it could be "/res/test.png", for example.

    Graham.

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Re: Image path

    No the image file s not in the jar manifest. What should I add in?

    Is there no way of telling the eclipse IDE to add it in atuoamtically?

  9. #9
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Image path

    It needs to be in the JAR, not the MANIFEST. Is it in the JAR?

    Yes, the IDE should include resource files for you. When you created the project, did it create a "res" folder for you? Or did you create the "res" folder?

    Are you using eclipseME or the Eclipse MTJ?

    Graham.

  10. #10
    Registered User
    Join Date
    Nov 2009
    Posts
    11

    Re: Image path

    The res folder was created automatically for me. I have copied the file test.png into that folder. I am using eclipseME.

    Thanks by the way for all your time on this

  11. #11
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Image path

    Hmmm... I'm at something of a loss.

    I'm not a regular eclipseME user. You might want to try running through this tutorial, just to check that it works and you don't have any problems with your set-up. Go straight to section 4 (start a new project). It should only take you about 10 minutes. Maybe you'll spot some step that you missed, or some option that you didn't pick?

    Graham.

Similar Threads

  1. Image Transparency issue
    By tomcruise in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2008-05-31, 15:46
  2. Image Transparency issue - Help me out ....
    By tomcruise in forum Mobile Java Games
    Replies: 2
    Last Post: 2008-05-31, 15:40
  3. Image or Sprite, thats the problem
    By Tiger79 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2007-10-02, 08:59
  4. saving jpeg image on grid list
    By flicker82 in forum Symbian
    Replies: 0
    Last Post: 2005-01-21, 04:22
  5. Loading Image data from 'raw' bytes
    By LongSteve in forum Mobile Java General
    Replies: 2
    Last Post: 2002-11-20, 17:38

Posting Permissions

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