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: 87
Registered: ‎08-25-2009
My Device: Not Specified
Accepted Solution

Adding locationPicker throws IllegalStateException

 

Thread [Ritis_Maps(180)id=253124608] (Suspended (exception IllegalStateException))    
    LocationPicker(Screen).setManager(Manager, int) line: 6219    
    VerticalFieldManager(Manager).insertInternal(Field, int) line: 2203    
    VerticalFieldManager(Manager).add(Field) line: 545    
    TitleStatusManager.add(Field) line: 609    
    AdvancedIncidentListOptions(Screen).add(Field) line: 288    
    AdvancedIncidentListOptions.addComponents() line: 147    
    AdvancedIncidentListOptions.<init>() line: 93    

 

 

I have a MainScreen in which I am adding my LocationPicker. I call add(locationPicker);

 

I call this method before, to set up the locationPicker.

 

 

private void readyLocationPicker(){
	Vector locationpick = new Vector();
	

	locationpick.addElement(GPSLocationPicker.getInstance());

	
	Landmark[] landmarks = new Landmark[1];
	landmarks[0] = new Landmark("DC Beltway", "Center of 495 Beltway", new QualifiedCoordinates(LATITUDE_CENTER_OF_DC_BELTWAY, LONGITUDE_CENTER_OF_DC_BELTWAY, Float.NaN, Float.NaN, Float.NaN), null);
	final SuggestedLocationPicker slp = SuggestedLocationPicker.getInstance("Suggested Locations...", landmarks);
	locationpick.addElement(slp);
	
	locationpick.addElement(EnterLocationPicker.getInstance(true));
	locationpick.addElement(MapsLocationPicker.getInstance());
	locationpick.addElement(RecentLocationPicker.getInstance());
	locationpick.addElement(ContactsLocationPicker.getInstance(true));

	LocationPicker.Picker[] locationPickersArray = new LocationPicker.Picker[locationpick.size()];
	locationpick.copyInto(locationPickersArray);

	locationPicker = LocationPicker.getInstance(locationPickersArray);
	locationPickListener = new LocationPicker.Listener() {
		
		public void locationPicked(Picker picker, Landmark location) {
			if(picker==slp){
				//TODO: Change radius field to 30 Miles
				choiceRadius.setSelectedValue(30);
			}
			System.out.println("Landmark: " + location);
		}
	};
	locationPicker.setListener(locationPickListener);
}

 

I have no idea what is going on, and why it won't work.

 

 

Thanks.

Developer
Posts: 87
Registered: ‎08-25-2009
My Device: Not Specified

Re: Adding locationPicker throws IllegalStateException

I can't figure this out, does anyone have a clue as to what may be causing this?

BlackBerry Development Advisor
Posts: 15,084
Registered: ‎07-09-2008
My Device: BlackBerry Passport
My Carrier: Bell

Re: Adding locationPicker throws IllegalStateException

From where are you calling readyLocationPicker?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 87
Registered: ‎08-25-2009
My Device: Not Specified

Re: Adding locationPicker throws IllegalStateException

[ Edited ]

 

        public AdvancedIncidentListOptions()
        {
        	readyComponents();
        	addComponents();
        }

 

The constructor for a subclass of MainScreen,

 

 

private void readyComponents(){
	readyLocationPicker();
	
	choiceRadius = new NumericChoiceField("Radius(mi):", 5, 50, 5, 2);

	timeNumber = new NumericChoiceField("", 1, 20, 1, 0){
		
		public void layout(int width, int height){
            super.layout(width,height);
            setExtent((getWidth()/5),20);       
        }

	};

.....
}

 

Then adding it screwed everything up:

 

 

private void addComponents(){
	LabelField lblLocation = new LabelField("Location:");
	lblLocation.setFont(Font.getDefault().derive(Font.BOLD, Font.getDefault().getHeight() + 2));
	add(new LabelField("Location:"));
	//PROBLEM: add(locationPicker);
	add(choiceRadius);

 

 

 

Developer
Posts: 87
Registered: ‎08-25-2009
My Device: Not Specified

Re: Adding locationPicker throws IllegalStateException

Where else could I put this so that it works, (if that is the problem)? Is this a general error that someone understands?

Developer
Posts: 87
Registered: ‎08-25-2009
My Device: Not Specified

Re: Adding locationPicker throws IllegalStateException

 Oh, it extends Screen. Silly me. Here's how I got it to work:

 

locationPickerButton = new ButtonField("Location", ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT);
locationPickerButton.setChangeListener(new FieldChangeListener() {
	public void fieldChanged(Field field, int context) {
		
		locationPicker.show();
        locationPickerButton.setLabel(locationPickerLocation.getName());
  
	}
});