×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    5

    Question N70 load PNG problem

    My J2ME game can't keep running after start. It seems stop at the load image process.
    I write a simple test program like this:

    public class loadPNGTest
    extends MIDlet
    implements Runnable {
    static loadPNGTest instance;
    Screen displayable = new Screen();
    public loadPNGTest() {
    Thread thread = new Thread(this);
    thread.setPriority(Thread.NORM_PRIORITY);
    thread.start();
    instance = this;
    }

    public void startApp() {
    Display.getDisplay(this).setCurrent(displayable);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
    }

    private long _frameInterval = 80;
    public void run() {
    long frameElapse, frameTick;
    try {
    frameTick = System.currentTimeMillis();
    while (true) {
    if (displayable != null && !displayable._painting) {
    frameElapse = System.currentTimeMillis() - frameTick;
    if (frameElapse < _frameInterval) {
    Thread.sleep(_frameInterval - frameElapse);
    }
    displayable.repaint();
    //_focus.serviceRepaints();
    frameTick = System.currentTimeMillis();
    }
    }
    }
    catch (Exception e) {
    }
    }
    }


    import javax.microedition.lcdui.*;
    import com.nokia.mid.ui.*;

    public class Screen
    extends FullCanvas {
    public Screen() {
    }

    public boolean _painting;
    private int _loadProcess;
    private Image _title, _menu, _navigation;
    static private byte[] fourbytes;

    static {
    fourbytes = new byte[4];
    }

    static private final String HallLOGOpng = "/res/logo.bin"; //LOGO resource file
    protected void paint(Graphics g) {
    _painting = true;
    _loadProcess++;
    g.setClip(0, 0, 176, 208);

    if (_loadProcess == 1) {
    _title = loadPng(HallLOGOpng, 0);
    g.drawImage(_title,
    (176 - _title.getWidth()) / 2,
    (208 - _title.getHeight()) / 2,
    g.LEFT | g.TOP);
    _menu = loadPng(HallLOGOpng, 1);
    _title = null;
    }
    else if (_loadProcess == 10) {
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, 176, 208);
    g.drawImage(_menu, 0, 0, g.LEFT | g.TOP);
    _navigation = loadPng(HallLOGOpng, 2);
    } else if ( _loadProcess == 30 ) {
    g.drawImage(_navigation, 0,0,g.LEFT|g.TOP);
    }

    _painting = false;
    /** @todo Add paint codes */
    }

    //load the PNG file from the packege file
    static public Image loadPng(String fileName, int inx) {
    Image img;
    byte[] data = readDataFile(fileName, inx);
    img = Image.createImage(data, 0, data.length);
    data = null;
    // System.gc();
    return img;
    }

    //read the appointed file
    static public byte[] readDataFile(String fileName, int id) {
    int number;
    int offset = 0;
    int len = 0;
    java.io.InputStream file;

    try {
    byte[] data = null;
    file = fileName.getClass().getResourceAsStream(fileName);
    file.read(fourbytes);
    number = readInt(fourbytes, 0, 4 );
    for (int i = 0; i < number; i++) {
    file.read(fourbytes);
    if (i == id) {
    offset = readInt(fourbytes, 0, 4 );
    }
    else if (i == (id + 1)) {
    len = readInt(fourbytes, 0, 4 ) - offset;
    }
    }
    file.skip(offset);
    data = new byte[len];
    file.read(data);
    return data;
    }
    catch (Exception e) {
    e.printStackTrace();
    //if(cDef._DEBUG_)System.out.println("Fatal Error:"+ "Couldn't create level from "+fileName);
    return null;
    }
    }

    static public int readInt(byte[] b, int off, int num) {
    int res = 0;
    for (int i = num - 1; i >= 0; i--) {
    res <<= 8;
    if (i == num - 1) {
    res |= b[i + off];
    }
    else {
    res |= b[i + off] & 0x00ff;
    }
    }
    return res;
    }
    }


    The program seems stop at the statement "_title = loadPng(HallLOGOpng, 0);" until I press the shift button and return the program.Why?

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,192

    Re: N70 load PNG problem

    Do you have the "logo.bin" file packaged inside the JAR file in the res directory?

    Hartti

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    5

    Re: N70 load PNG problem

    Thanks for your answer!
    Yes! JAR include the resource file which named "logo.bin"
    If not have, the program will throw a exception, but my program have not any exception, it seems be stopped at load image process !
    It became fine when I pressed the shift button and back to the program.
    The problem also exist after I replace the statement "_title = loadPng(HallLOGOpng, 0);" whith "_title = Image.createImage("/res/title.png");" !

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    5

    Re: N70 load PNG problem

    By the way, my program can running in other mobile phones except N70

Similar Threads

  1. MP4 video playback problem with N70...
    By Mattloaf in forum Streaming and Video
    Replies: 9
    Last Post: 2010-05-05, 16:09
  2. Replies: 3
    Last Post: 2006-11-13, 08:22
  3. N70 Ringtone problem
    By gambit808 in forum Audio
    Replies: 5
    Last Post: 2006-05-10, 08:39
  4. SMS viewing problem with N70
    By Tripoff in forum Mobile Java General
    Replies: 1
    Last Post: 2005-12-09, 18:22
  5. Load Png file
    By lilesh in forum Symbian User Interface
    Replies: 0
    Last Post: 2005-01-20, 12:49

Posting Permissions

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