0 Replies Latest reply: Jul 10, 2012 4:27 AM by VANPERSIE RSS

    The application does not use the  screen and run in the background

    VANPERSIE
      Hi

      I have downloaded a package of j2me Midlet
      from [link] here [link]
      and try to reuse the code
      but I get the following error when running the code:-

      The application does not use the screen and run in the background

      I think the error into one of these two classes
      package main;
      import javax.microedition.midlet.*;
      
       
      import javax.microedition.midlet.*;
      import javax.microedition.lcdui.*;
      import javax.microedition.media.Manager;
      import javax.microedition.media.MediaException;
      import javax.microedition.media.Player;
      import java.io.IOException;
      import java.io.InputStream;
      
       
      public class MainMidlet extends MIDlet implements CommandListener {
          private SSGameCanvas gameCanvas ;
          private Command exitCommand ;
          private Player player = null;
      
      
          public void startApp() {
        try {
             //   create new game thread
                gameCanvas = new SSGameCanvas();
                gameCanvas.start(); // start game thread
                exitCommand = new Command("Exit",Command.EXIT,1);
                gameCanvas.addCommand(exitCommand);
                gameCanvas.setCommandListener(this);
                  Display.getDisplay(this).setCurrent(gameCanvas);
                         
          }
         catch (java.io.IOException e)
             {
                  e.printStackTrace();
            }
              try {
                  // start sounds
                  InputStream in = getClass().getResourceAsStream("/resource/startfly.wav");
                  player = Manager.createPlayer(in,"audio/x-wav");
                  player.setLoopCount(1);
                  player.start();
      
              } 
              catch (MediaException ex)
              {
                  ex.printStackTrace();
              }
               catch (IOException ex)
               {
                  ex.printStackTrace();
              }
          }
      
      
          public void pauseApp() {
          }
      
          public void destroyApp(boolean unconditional) {
              if (player != null) {
                  player.close();
              }
              System.gc();
          }
      
      
        public void commandAction(Command command, Displayable displayable) {
             if (command == exitCommand)
              {
                   destroyApp(true);
                   notifyDestroyed();
              }  }
      
          }
       
      package main;
      import java.io.IOException;
      import javax.microedition.lcdui.*;
      import javax.microedition.lcdui.game.*;
       
      public class SSGameCanvas extends GameCanvas implements Runnable {
          protected GameManager gameManager;
          protected boolean running;
          private int tick=0;
          private static int WIDTH;
          private static int HEIGHT;
          private int mDelay = 20;
          Form mainForm;
          Display display;
          //private int MaxTime;
          public SSGameCanvas() throws IOException{
              super(true);
              gameManager = new GameManager(5,5,getHeight()-10,getWidth()-10,this);
          }
          public void start() {
             
      
      
                  this.running = true;
                  Thread t = new Thread(this);
                  t.start();
          }
      
          public void stop() {
              running = false;
      
          }
      
          public void render(Graphics g) {
              WIDTH = getWidth();
              HEIGHT = getHeight();
              // Clear the Canvas.
              g.setColor(0, 0, 50);
              g.fillRect(0,0,WIDTH-1,HEIGHT-1);
              // draw border
              g.setColor(200,0,0);
              g.drawRect(0,0,WIDTH-1,HEIGHT-1);
              // draw game canvas
              gameManager.paint(g);
          }
          public void run() {
      
              while (running) {
                  // draw graphics
                  render(getGraphics());
                  // advance to next graphics
                  advance(tick++); 
                  // display
                  flushGraphics();
                  try { Thread.sleep(mDelay); }
                  catch (InterruptedException ie) {}
              }
          }
      
          public void advance(int ticks) {
              // advance to next game canvas
              gameManager.advance(ticks);
              this.paint(getGraphics());
          }
      }
      Edited by: VANPERSIE on Jul 10, 2012 12:26 PM