×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    18

    Unable to use a "back" button

    I am having problems trying to use a back button. I want to be able to use a button to go back to the previous screen, but it does not seem to work right.



    Within the "Welcome Form" I create an instance of the "Options Form", and then this calls the correct method when the options form.

    if (c == CMD_OPTIONS_PAGE) {
    display.setCurrent(optionsForm.viewOptionsForm(resumeScreen));
    }


    In the options form I have set the value passed in "resumescreen" equal to "this.backscreen" in the object. When the "back" button is hit in the "options form", it sets the display back to "this.backscreen".


    try {
    if (c == backCommand) {
    display.setCurrent(this.backScreen);
    }
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }


    I am not really sure why this does not work, i have output the "backscreen.getTitle()" and this returns "Final Year Proejct", which is the title of the "welcome form".


    Does anybody have any examples or help??

    Thanks

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Unable to use a "back" button

    Hi,
    Check that both,your command and the displayable are not null.While you are setting the setCurrent() item then it is not throwing any exception.

    Surely there will be any exception..

    Thanks
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Jul 2008
    Location
    Faridabad(Delhi NCR)
    Posts
    343

    Re: Unable to use a "back" button

    There are number of reason why this problem coming first one is told by raj...
    firstly use System.out.print inside
    if condition and check whether its cuming inside or not if it is not coming then
    check did u set set command listener for this form.if it is not then firstly set command listener...
    second check what is your displayble .....and can u please write ur whole code here so we can easily tell
    Anshu Chauhan
    J2me Developer

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    18

    Re: Unable to use a "back" button

    This is my code.

    WELCOMEFORM.JAVA



    package project.test.forms;

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;

    public class WelcomeForm extends MIDlet implements CommandListener {

    private static final Command CMD_EXIT = new Command("Exit", Command.EXIT, 2);
    private static final Command CMD_OPTIONS_PAGE = new Command("Options Page", Command.ITEM, 1);
    private static final Command CMD_GOOGLE_MAPS = new Command("Google Maps", Command.ITEM, 1);
    private static final Command CMD_GET_LOCATION = new Command("Get Location", Command.ITEM, 1);
    private static final Command CMD_SHOW_CATEGORIES = new Command("Categories Form", Command.ITEM, 1);
    private static final Command CMD_CHOOSE_CATEGORIES = new Command("Choose Default Categories", Command.ITEM, 1);
    private Display display;
    private Form mainForm;
    private OptionsForm optionsForm = new OptionsForm();
    private GPSForm gpsForm = new GPSForm();
    private GetLocation getLocation = new GetLocation();
    private CategoriesForm categoriesForm = new CategoriesForm();
    private ChangeCategories changeCategories = new ChangeCategories();
    Displayable resumeScreen = null;

    public WelcomeForm() {
    mainForm = new Form("Final Year Project");
    display = Display.getDisplay(this);
    mainForm.append("Please select an options from the menu below");
    mainForm.addCommand(CMD_EXIT);
    mainForm.addCommand(CMD_OPTIONS_PAGE);
    mainForm.addCommand(CMD_GOOGLE_MAPS);
    mainForm.addCommand(CMD_GET_LOCATION);
    mainForm.addCommand(CMD_SHOW_CATEGORIES);
    mainForm.addCommand(CMD_CHOOSE_CATEGORIES);
    mainForm.setCommandListener(this);
    resumeScreen = mainForm;
    }

    protected void startApp() {
    display.setCurrent(resumeScreen);
    }

    protected void destroyApp(boolean unconditional) {
    }

    protected void pauseApp() {
    resumeScreen = display.getCurrent();
    }

    public void commandAction(Command c, Displayable d) {

    if (c == CMD_OPTIONS_PAGE) {
    display.setCurrent(optionsForm.viewOptionsForm(resumeScreen));
    }

    if (c == CMD_GOOGLE_MAPS) {
    display.setCurrent(gpsForm.showmap(d));
    }

    if (c == CMD_GET_LOCATION) {
    display.setCurrent(getLocation.currentLoction(d));
    }

    if (c == CMD_SHOW_CATEGORIES) {
    display.setCurrent(categoriesForm.viewCategoriesForm(mainForm));
    }

    if (c == CMD_CHOOSE_CATEGORIES) {
    display.setCurrent(changeCategories.setCategories(resumeScreen));
    }

    if (c == CMD_EXIT) {
    destroyApp(false);
    notifyDestroyed();
    }
    }
    }







    This is the class that I am trying to get working. I have several class all with back buttons and none seem to work.

    OPTIONSFORM.JAVA



    package project.test.forms;

    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;

    public class OptionsForm implements CommandListener, ItemCommandListener, ItemStateListener {

    private Form mainOptionsForm;
    Command backCommand = new Command("Back", Command.BACK, 2);
    private static final Command CMD_SELECT = new Command("Select", Command.ITEM, 1);
    Displayable backScreen;
    private Display display;
    CategoriesForm categoriesForm = new CategoriesForm();

    public OptionsForm() {
    }

    protected void startApp() {
    }

    protected void destroyApp(boolean unconditional) {
    }

    protected void pauseApp() {
    }

    public Form viewOptionsForm(Displayable backScreen) {

    this.backScreen = backScreen;

    mainOptionsForm = new Form("viewOptionsPage");
    mainOptionsForm.append("viewOptionsPage");

    StringItem item = new StringItem("This is a StringItem label: ", "This is the StringItems text");
    mainOptionsForm.append(item);

    mainOptionsForm.append("backScreen.getTitle()" + backScreen.getTitle());
    mainOptionsForm.append("backScreen.toString()" + backScreen.toString());

    // these are the images and strings for the choices.
    Image[] imageArray = null;
    String[] stringArray = {"Option A", "Option B", "Option C", "Option D"};

    String[] timeToWalk = {"1 min", "2 mins", "3 min", "4 mins", "5 mins", "6 mins", "7 mins", "8mins", "9 mins", "10 mins", "15 mins", "20 mins"};
    String[] updates = {"True", "False"};
    // create the list of choice groups.
    ChoiceGroup[] groups = {
    new ChoiceGroup("Time To Walk", ChoiceGroup.POPUP, timeToWalk, imageArray),
    new ChoiceGroup("Automatic Updates", ChoiceGroup.POPUP, updates, imageArray),
    new ChoiceGroup("Pop-Up-3", ChoiceGroup.POPUP, stringArray, imageArray)
    };

    for (int iter = 0; iter < groups.length; iter++) {
    mainOptionsForm.append(groups[iter]);
    }


    item = new StringItem(null, "View Default Categories", Item.BUTTON);
    item.setDefaultCommand(CMD_SELECT);
    item.setItemCommandListener(this);
    mainOptionsForm.append(item);

    mainOptionsForm.addCommand(backCommand);
    mainOptionsForm.setCommandListener(this);


    return mainOptionsForm;
    }

    public void commandAction(Command c, Item item) {
    if (c == CMD_SELECT) {
    //display.(categoriesForm.viewCategoriesForm());
    }
    }

    public void commandAction(Command c, Displayable d) {
    try {
    if (c == backCommand) {
    //maybe screen is loaded behind
    //Close this screen first
    display.setCurrent(this.backScreen);
    }
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    }

    public void itemStateChanged(Item arg0) {
    throw new UnsupportedOperationException("Not supported yet.");
    }
    }



    Any ideas, when i run the application in the options form i ask it to print out "mainOptionsForm.append("backScreen.getTitle()" + backScreen.getTitle());" this prints "Final Year Project", which is the title of the welcome form ("mainForm = new Form("Final Year Project");")

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Unable to use a "back" button

    Hi,
    Your code is not complete ...what these lines stand for..You must have missed code.

    private GPSForm gpsForm = new GPSForm();
    private GetLocation getLocation = new GetLocation();
    private CategoriesForm categoriesForm = new CategoriesForm();
    private ChangeCategories changeCategories =new ChangeCategories();

    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Bangalore, India
    Posts
    47

    Re: Unable to use a "back" button

    Hi marc_garraway,

    I think u didn't provide much attention to what the other posters was asking you to do. Had u did that, u could have sort out the problem i.e. your Display object in class OptionsForm is never initialized and hence is throwing a NullPointer exception which though u happen to have handled in a try catch block !!

    I think you can solve it now that the problem is clear.
    Regards,
    S.D.

Similar Threads

  1. CEikRichTextEditor unable to respond to "C" button
    By raysky in forum Symbian User Interface
    Replies: 6
    Last Post: 2008-12-04, 08:27
  2. Add a control (e.g. button) programmatically
    By ViRuSTriNiTy in forum Symbian User Interface
    Replies: 2
    Last Post: 2008-01-02, 21:05
  3. Nokia 6600's "Red" keypad button unable to closed application.
    By tsoh_tan in forum Mobile Java General
    Replies: 1
    Last Post: 2004-01-15, 08:17
  4. how to replace the "back" button with the menu?
    By yinjialiang in forum Symbian User Interface
    Replies: 9
    Last Post: 2003-10-28, 06:33

Posting Permissions

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