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
Developer
Posts: 34
Registered: ‎07-30-2013
My Device: Curve 9300
My Carrier: CellC
Accepted Solution

IllegalStateException when loading a screen

Me again. Don't worry, I'm almost done with my app, and I am leaving for a nice well deserved long weekend tomorrow morning early Smiley Happy

 

Anyways. On my first screen I call this code :

 

	public void fieldChanged(Field field, int context) {
		// TODO Auto-generated method stub
		 if(field == ContactButton)
		    {
			 
			 UiApplication.getUiApplication().pushScreen(new Contact());
		    }
		 else if (field == DownloadButton)
		 {       
		        UiApplication.getUiApplication().pushScreen(new DownloadScreen());
		        
		 }
		 
		 
	}

 On my Contact button, once pressed, I get an IllegalStateException. The Download button shows the screen and all other ListField events work nicely

 

What can be wrong?

 

Hannes

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: IllegalStateException when loading a screen

there is issue in your Contact() screen, check there or please provide us code for the same screen?
Developer
Posts: 34
Registered: ‎07-30-2013
My Device: Curve 9300
My Carrier: CellC

Re: IllegalStateException when loading a screen

I cannot seem to find any anomaly with this class :

 

public class ContactScreen extends MainScreen implements FieldChangeListener {
/** * Creates a new MyScreen object */
ButtonField SendButton = new ButtonField("Send", ButtonField.CONSUME_CLICK);
EditField txtName = new EditField();
EditField txtEmail = new EditField();
EditField txtCell = new EditField();
EditField txtMessage = new EditField();
public ContactScreen()
{ // Set the displayed title of the screen
// create a label
LabelField title = new LabelField("Contact Us", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
// create a label
LabelField lblName = new LabelField("Please Enter Your Name",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
LabelField lblEmail = new LabelField("Please Enter Your Email Address",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
// create a label
LabelField lblCell = new LabelField("Please Enter Your Telephone Number",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
// create a label
LabelField
lblMessage = new LabelField("Please Enter Message",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);

SendButton.setChangeListener(this);
VerticalFieldManager
vfm = new VerticalFieldManager(Field.FIELD_VCENTER);

vfm.add(title);
vfm.add(lblName);
vfm.add(txtName);
vfm.add(lblEmail);
vfm.add(txtEmail);
vfm.add(lblCell);
vfm.add(txtCell);
vfm.add(lblMessage);
vfm.add(txtMessage);
vfm.add(SendButton);
add(vfm);
setTitle(title);
}

public void TextMailSend() {
String message = txtMessage.getText() + System.getProperty("line.separator") +
txtName.getText() +
System.getProperty("line.separator") +
txtCell.getText() +
System.getProperty("line.separator") +
txtEmail.getText();

Message msg = new Message();
try {
final Address address = new Address("user@somewhere.domain","us");
Address[] addresses = {address};
msg.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, addresses);
msg.setContent(message);
msg.setSubject("Course Enquiry");

Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(msg));

Dialog.inform("Mail Sent Successfully.");

}
catch (AddressException e) {
e.printStackTrace();

Dialog.inform(e.getMessage());
}
catch (MessagingException e) {
e.printStackTrace();
Dialog.inform(e.getMessage());
}
}
public void fieldChanged(Field arg0, int arg1) {
// TODO Auto-generated method stub
if(arg0 == SendButton)
{
TextMailSend();
}
}
protected boolean keyDown(int keycode, int status)
{
if(Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
UiApplication.getUiApplication().pushScreen(new NccBMainScreen());
UiApplication.getUiApplication().popScreen(ContactScreen.this);
return true;
}
return false;
}
}

 The above is for my COntactScreen

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: IllegalStateException when loading a screen

remove this from ur code :

setTitle(title);

and try?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: IllegalStateException when loading a screen

[ Edited ]

Two suggestions for IllegalStateException:

 

a) Put a try/catch around and print the detail message - it contains some additional information that will help identify the problem.

 

b) Debug the application.  When you running in debug and you don't have a try catch, it will stop at the point of failure and then you look at the stack trace to see what instruction in your program caused the error.  So do this one now, the try catch will be useful later when you aren't debugging. 

 

PS.

 

Just seen the suggestion above.  My recommendation, don't bother trying it.  From my reading, I would be very confident that is not the problem - and why guess when by debugging we can find out exactly what the problem is. 

 

Edit:

 

Humble pie - I was wrong - apologies......  I missed it being there twice as well. 

Developer
Posts: 34
Registered: ‎07-30-2013
My Device: Curve 9300
My Carrier: CellC

Re: IllegalStateException when loading a screen

It tells me Field added to manager while it is already added to a parent.

I'll look more closely
Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: IllegalStateException when loading a screen

you are adding title two times so comment this setTitle(title); in your code

one you are adding in vfm like this vfm.add(title);
and second setTitle(title);
Developer
Posts: 34
Registered: ‎07-30-2013
My Device: Curve 9300
My Carrier: CellC

Re: IllegalStateException when loading a screen

You know what, I think I'm going blind - I cannot believe I missed this. I am usually much better than this at troubleshooting and coding - I think my mind is already on holiday.

HanneS ThE **bleep** Smiley Happy