×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    14

    Red face Help locating resources from res folder

    Hi, this should be a simple question - but can smeone confirm how images etc called from the resource (res) folder. For example, I usually use the following code which works great in sun wtk emulator but isnt working in the series 40 emulator and real 6280. It doesn't work with my N70 device, fails to find image.

    try
    {
    ufoSprite = new Sprite(Image.createImage("/ufo.png"));
    ufoSprite.setPosition(0, 0);
    }
    catch (IOException e)
    {
    showAlert("Failed loading image!");
    }

    Seems normal to me. I've tried using a full system address, relative addresses, and package address. Ive seen similar code in Nokia docs, can someone just fill me in with the proper way. Do I need to sign the midlet first (hope not!)

    *I've doubly-doubly checked that the image is there, it's in normal vanilla ping format, isn't transparent just in case, and not currently opened in an editor. It works perfectly in sun wtk and SonyEric emulator. It's definitely there! *

    PS: I replaced my 6280 with a N70 this morning and found that all but one of my games (about 14) don't work anymore! They open and then close right away. But the MMAPI app I struggled with yesterday works on the N70 like a charm! You win some...

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Brazil
    Posts
    1,884

    Re: Help locating resources from res folder

    Hi imational,

    Image image = Image.createImage("/ufo.png"); should work...

    Check that:

    http://www.onjava.com/pub/a/onjava/e...x2.html?page=4

    BR,

    Juarez Jr

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    14

    Re: Help locating resources from res folder

    Hi Juarez Jr

    Thanks for your advice. I agree it should work and the code does work EVERYWHERE except when I try it on the Nokia emulators and devices. It's so odd...

    supplying ("\imageName.png") to the image constructor is enough to identify the image as in the resource folder (rsc), isn't it? Yet the Nokia software is unable to find the file.

    If I use the Sun WTk or SonyEric emulator it runs fine. There's something I'm missing, maybe I'll try adjusting the image or something.?

    Ryan.

  4. #4
    Super Contributor
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,191

    Re: Help locating resources from res folder

    Stupid question: Have you packaged the file in the jar file you are installing on the device? Open the .jar file with WinZip and see if ufo.png is there. Or use jar from command line:

    jar tf MyMidlet.jar

    Hartti

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    14

    Re: Help locating resources from res folder

    Hi Hartti,

    Yes I unpacked the jar file and the image file is definitely in there. The jar is working with other emulators.

    Here is the stripped down version of the canvas code - it couldn't get any simpler. An imaginary brilliant prize is up for grabs to the person who spots whtever my stupid mistake is!

    A nullpointerexception is thrown at the createimage(..) command. I changed the ufo.png to van.png since i know it's fine.

    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    import javax.microedition.lcdui.game.Sprite;
    import java.util.*;
    import java.io.*;

    public class UFOCanvas extends GameCanvas implements Runnable {
    private Display screendisplay;
    private boolean sleeping;
    private long frameDelay;
    private Sprite ufoSprite = null;

    public UFOCanvas(Display d) {
    super(true);
    screendisplay = d;

    // Set the frame rate (30 fps)
    frameDelay = 33;
    }

    public void startGame() {
    // Set the canvas as the current screen
    System.out.println("This is the beginning");
    screendisplay.setCurrent(this);

    try
    {
    System.out.println("Entered the createimage bit");
    Image spriteImage = Image.createImage("/van.png");
    System.out.println("Should have created the image");
    ufoSprite = new Sprite(spriteImage);
    System.out.println("Should have created the sprite");
    }
    catch (IOException e)
    {
    showAlert("Failed loading image!");
    }

    // Start the animation thread
    sleeping = false;
    Thread t = new Thread(this);
    t.start();
    }

    public void stop() {
    // Stop the animation
    sleeping = true;
    }

    public void run() {
    Graphics g = getGraphics();

    // The main game loop
    while (!sleeping) {
    gameUpdate();
    gameDraw(g);
    try {
    Thread.sleep(frameDelay);
    }
    catch (InterruptedException ie) {}
    }
    }

    private void gameUpdate() {
    }

    private void gameDraw(Graphics g) {
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(0x000000);
    g.drawString("Well done!",
    getWidth()/2, getHeight()/2,
    Graphics.HCENTER | Graphics.BASELINE);

    System.out.println("Should have positioned the sprite");
    ufoSprite.setPosition(80, 80);
    // Draw the sprite
    ufoSprite.paint(g);
    // Flush the offscreen graphics buffer
    flushGraphics();
    }

    public void showAlert(final String message)
    {
    new Thread()
    {
    public void run()
    {
    Alert alert = new Alert("Uh oh" + message);
    alert.setTimeout(1500);
    screendisplay.setCurrent(alert);
    }
    }.start();
    }
    }
    ................................
    output:
    Using Untrusted simulated domain
    This is the beginning
    Entered the createimage bit
    Should have positioned the sprite
    Uncaught exception java/lang/NullPointerException.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    14

    Re: Help locating resources from res folder

    Right... SLIGHT update

    Changed the filename from van.png to van.PNG and it now runs on series 40 emulator. Progress.

    However.... still will not run on Nokia N70 device - shows custom alert "Uh-oh! Failed loading image!"

    What's different between series 40 and series 60 implementations?


  7. #7
    Registered User
    Join Date
    Sep 2004
    Posts
    14

    Talking **Problem Solved**

    It was all to do with the case of the "png" extension

    I use fireworks for my graphics, and I found out that it automatically saves image files with a capital "PNG" extension. What I didn't realise is that this is case sensitive in the series 40 emulator and n70 phone. So when I changed my code to include the capital "PNG" it worked fine in the series 40 emulator.

    Now get this - the N70 wouldn't recognize the capital "PNG" at all. So even though my code was changed to reflect the capitals, the N70 couldn't find the image because it was only looking for the lower case "png". Is this normal??? (as it feels like a bug or an oversight to me)

    Anyway, I loaded the graphic into MS Paint, saved it with a small "png" and now I can read it fine in the Nokia N70 handset. And it only took 13 hours to work that out!!!

    I hope this note will save someone else a bit of time in the future. Thanks again for everyone who replied.

Similar Threads

  1. Game directly to Game Folder
    By JPurd in forum Mobile Java General
    Replies: 4
    Last Post: 2008-04-15, 20:34
  2. Replies: 1
    Last Post: 2003-10-14, 13:47
  3. How to automatically copy files from soruce folder to BUILD folder
    By etccoch111 in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-10-14, 09:13
  4. Replies: 0
    Last Post: 2003-10-14, 04:37
  5. Replies: 0
    Last Post: 2002-09-27, 06:55

Posting Permissions

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