×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15

    Midlet won't exit!

    Hi

    I've made this midlet and it won't exit when I press the exit button.. the only way i can stop it is by pressing the on/off switch or the end call button. I don't have a clue why its not letting me exit so could anyone have a look at my code and tell me what's wrong? it's probably glaringly obvious....

    Code:
    package GPSreader;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    
    public class WebMap extends MIDlet implements CommandListener{
      Alert alert;
      public String position1;
      public String position2;
      private Display display ;
    
      public DataHandler dh;
      private Form form = new Form("Form for Stuff");
      static final Command exitCommand = new Command("Exit", Command.STOP, 2);
    
      public void startApp() throws MIDletStateChangeException{
        boolean b;
       
    
      try{
        display = Display.getDisplay(this);
        display.setCurrent(form);
        form.addCommand(exitCommand);
        form.setCommandListener(this);
        form.append("position 1:");
        position1 = dh.getLat();
        form.append(position1);
      }      catch(Exception e){
        System.out.println("error:"+e.toString());
      }
         
      }
    
      public void pauseApp() {
      }
    
      public void destroyApp(boolean unconditional) {
        destroyApp(true);
        notifyDestroyed();
      }
    
      public void commandAction(Command choice, Displayable displayable ) {
        String label = choice.getLabel();
        if (label.equals("Exit")) {
          destroyApp(true);
          notifyDestroyed();
        }
      }
    }

  2. #2
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: Midlet won't exit!

    Quote Originally Posted by andybeeeeee

    Code:
    package GPSreader;
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    
    public class WebMap extends MIDlet implements CommandListener{
      Alert alert;
      public String position1;
      public String position2;
      private Display display ;
    
      public DataHandler dh;
      private Form form = new Form("Form for Stuff");
      static final Command exitCommand = new Command("Exit", Command.STOP, 2);
    
    Usually this is Command.EXIT, but that shouldnt hurt, or affect anything
    
      public void startApp() throws MIDletStateChangeException{
        boolean b;
     
    you dont need to throw the midletstatechange exception, unless your
     trying to dissuade the user from closing the application, 
    if your not trying to stop the user from exiting the 
    application get rid of it  
    
      try{
        display = Display.getDisplay(this);
        display.setCurrent(form);
        form.addCommand(exitCommand);
        form.setCommandListener(this);
        form.append("position 1:");
        position1 = dh.getLat();
        form.append(position1);
      }      catch(Exception e){
        System.out.println("error:"+e.toString());
      }
         
      }
    
      public void pauseApp() {
      }
    
      public void destroyApp(boolean unconditional) {
        destroyApp(true);
        notifyDestroyed();
      }
    
      public void commandAction(Command choice, Displayable displayable ) {
        String label = choice.getLabel();
        if (label.equals("Exit")) {
          destroyApp(true);
          notifyDestroyed();
        }
      }
    }
    the two bolded, destroyapps? wouldnt this cause a neverending loop? you just need destroy app in your command action method, you migh have the second one, in destroy app, if you were using the midletstatechangeexception to prevent exiting of the app but then you would have the one in command, i belive be destroyapp(false), and the one in destroyapp method would be destroyapp(true) after you had (or if you wanted to) accomplished something before the true exiting of the app

    if you find a simple helloworld app, it will give you a nice midlet skeleton, you can use for future projects
    Jason Glass
    http://IChiBanComputers.Com

  3. #3
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: Midlet won't exit!

    Please modify the destroyApp() as below and only use only one destroyApp() in a MIDLET.

    public void destroyApp(boolean unconditional) {}

    Hope this helps.

    Regards
    Gopal

  4. #4
    Registered User
    Join Date
    Mar 2006
    Location
    Somewhere, England
    Posts
    15

    Re: Midlet won't exit!

    thanks for your help guys, cant believe i didnt see that...... staring at code for hours on end makes it harder to see where i went wrong!

  5. #5
    Super Contributor
    Join Date
    Mar 2006
    Location
    Phoenix, AZ. USA
    Posts
    556

    Re: Midlet won't exit!

    annnnddyyy (said with an Aunt Bee voice, i.e. from Andy griffith or whatever show)
    Jason Glass
    http://IChiBanComputers.Com

Similar Threads

  1. calling midlet from midlet throws SecurityException on 6600
    By brianpegan in forum Mobile Java General
    Replies: 3
    Last Post: 2010-10-25, 05:31
  2. N70 Reset bug
    By sebboB in forum General Development Questions
    Replies: 2
    Last Post: 2005-12-28, 23:09
  3. UNDESIRED Exit command key.
    By tektronic in forum Mobile Java General
    Replies: 4
    Last Post: 2005-05-13, 18:27
  4. 'Response Unknown' when downloading midlet
    By Weevil in forum Mobile Java General
    Replies: 3
    Last Post: 2004-05-30, 17:01
  5. Exit not working in a midlet
    By ferozekadamapuzha in forum Mobile Java General
    Replies: 2
    Last Post: 2003-06-06, 05: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
  •  
×