Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 8
Registered: ‎08-23-2011
My Device: Blackberry Curve 8520
My Carrier: Orange
Accepted Solution

Pushing and Popping Screen Not Working

HI, when I select my options and click on the button, I want it to close the current screen, and open up a different screen, but I get the error NullPointerException.

// Add Selected Field Change
	    HorizontalFieldManager hfm5 =  new HorizontalFieldManager(Field.FIELD_HCENTER | Field.FIELD_VCENTER);
	    final String choices[] = {"General","On The Course","On The Tee","On The Green","In The Bunker"};
	    final ObjectChoiceField objsel = new ObjectChoiceField("Select a Chapter",choices,0);
	    hfm5.add(objsel);
	    add(hfm5);
	   	    	    
	    
	 // Add Button To Page   
	    HorizontalFieldManager hfm4 =  new HorizontalFieldManager(Field.FIELD_HCENTER | Field.FIELD_VCENTER);
	    ButtonField mySubmitButton = new ButtonField("Tee Off",ButtonField.CONSUME_CLICK);
        hfm4.add(mySubmitButton);
        add(hfm4);
        
        mySubmitButton.setChangeListener(new FieldChangeListener(){
        	public void fieldChanged(Field Field, int context){  
        		final String selectedValue = choices[objsel.getSelectedIndex()];
        		if(selectedValue.equals("General"))
                {
        		General general = new General(); 	 
       	        UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
                UiApplication.getUiApplication().pushScreen(general);
                }
        		
        		else if(selectedValue.equals("On The Course"))
                {
        		OnCourse oncourse = new OnCourse(); 	 
       	        UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
                UiApplication.getUiApplication().pushScreen(oncourse);
                }
        		
        		else if(selectedValue.equals("On The Tee"))
                {
        		OnTee ontee = new OnTee(); 	 
       	        UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
                UiApplication.getUiApplication().pushScreen(ontee);
                }
        		
        		else if(selectedValue.equals("On The Green"))
                {
        		OnGreen ongreen = new OnGreen(); 	 
       	        UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
                UiApplication.getUiApplication().pushScreen(ongreen);
                }
        		
        		else if(selectedValue.equals("In The Bunker"))
                {
        		InBunker inbunker = new InBunker(); 	 
       	        UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
                UiApplication.getUiApplication().pushScreen(inbunker);
                }
        		
        		}});

 

MaxJMay
Developer
Posts: 16,680
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Pushing and Popping Screen Not Working

use the debugger and find out where the nullpointer is thrown.

you can also just use close() to close the current screen.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 18
Registered: ‎03-01-2011
My Device: 9800 Torch

Re: Pushing and Popping Screen Not Working

Try to:
1) pushScreen(newScreen);
2) popScreen(oldScreen);
Black Bee Team
New Contributor
Posts: 8
Registered: ‎08-23-2011
My Device: Blackberry Curve 8520
My Carrier: Orange

Re: Pushing and Popping Screen Not Working

I tried pushing the new screen, and then popping the old screen but I still get the same error. I tried debugging and it higlighted the
General general = new General();
part of my code.
MaxJMay
Developer
Posts: 16,680
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Pushing and Popping Screen Not Working

you can step into code, most likely the constructor has a nullpointer somewhere.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 18
Registered: ‎03-01-2011
My Device: 9800 Torch

Re: Pushing and Popping Screen Not Working

[ Edited ]

1) check your General() class for NullPointers
2) publish your stacktrace here

 

3)  publish your General() class here too 

Black Bee Team
New Contributor
Posts: 8
Registered: ‎08-23-2011
My Device: Blackberry Curve 8520
My Carrier: Orange

Re: Pushing and Popping Screen Not Working

Hi everyone, managed to solve my problem, on my General screen, I was drawing a picture on the screen, but hadn't chosen one yet, so left the file name blank. When I deleted this it worked.
Cheers,
Max.
MaxJMay