BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Push a new screen on a menu item select - Beginner help (http://www.blackberryforums.com/developer-forum/225354-push-new-screen-menu-item-select-beginner-help.html)

karthikus 04-28-2010 06:00 AM

Push a new screen on a menu item select - Beginner help
 
Guys i am very new to the world of blackberry. I have one question now. I have created a small application where i will have a MAIN screen displaying some components. But when the user presses the menu and select a menu option i need to push another screen containing different set of components.My sample code is as follows


Code:


public class ContactMain extends UiApplication {

        public static void main(String[] args) {

                ContactMain contactMain = new ContactMain();
                contactMain.enterEventDispatcher();
        }

        public ContactMain() {
                pushScreen(new ContactMainScreen());
        }

}


--------------------------


final class ContactMainScreen extends MainScreen {

        //components declaration


        public ContactMainScreen() {

          //initialize components

        }

        protected void makeMenu(Menu menu, int instance) {
                menu.add(addContact);
               
        }

        private MenuItem addContact = new MenuItem("Add Contact", 110, 10)                     
        {
                public void run() {
                        UiApplication.getUiApplication().(new ContactAddScreen());
                }
        };

}



----------------------------------------




final class ContactAddScreen extends MainScreen {


        //components declaration

        public ContactAddScreen() {

                    //initialize components

        }
}

--------------------------------------------------

But as soon as i press the menu i am getting a null pointer exception .

please help

Dougsg38p 04-28-2010 09:20 AM

This:

UiApplication.getUiApplication().(new ContactAddScreen());

Should be:

UiApplication.getUiApplication().pushScreen(new ContactAddScreen());


All times are GMT -5. The time now is 04:57 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.