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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

method cannot be called from event thread

what I want to do is have the a map open with the click of a buttonfield with two Criteria's, the user must either specify the location and then the image must be added to the location otherwise the Image must be added to the users current location.

The problem I am having is adding both criterias into an if statement in a thread / new thread or even in a FieldChangeListener.

The error I keep getting is: Error in location :javax.microedition.location.LocationException: getLocation() method cannot be cal[0.0] led from event thread [0.0] Error in location :getLocation() method cannot be called from event thread

MY Code:

    FieldChangeListener Listener = new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        ButtonField buttonClicked = (ButtonField) field;
        if ((buttonClicked.getLabel()).equals("Push")) {
            CustomMapField mMapField;
            Coordinates mCoordinates;
            BlackBerryCriteria blackBerryCriteria = null;
            BlackBerryLocation blackBerryLocation = null;
            BlackBerryLocationProvider blackBerryLocationProvider = null;
            double Doublelat = 0.0;
            double Doublelng = 0.0;
            blackBerryCriteria = new BlackBerryCriteria();
            if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)){
                    blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSITE);
            }else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)){
                blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST);
            }else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)){
                blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS);
            }else{
                blackBerryCriteria.setCostAllowed(true);
                blackBerryCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
            } try {
                blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryCriteria);
                blackBerryLocation = (BlackBerryLocation) blackBerryLocationProvider.getLocation(60);
                QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();

                Doublelat = qualifiedCoordinates.getLatitude();
                Doublelng = qualifiedCoordinates.getLongitude();
                mCoordinates = new  Coordinates(Doublelat, Doublelng, 0);
                mMapField = new CustomMapField();
                mMapField.mIcon = Bitmap.getBitmapResource("coin_silver.png");
                mMapField.moveTo(mCoordinates);
                mMapField.setZoom(1);
                add(mMapField);
             }catch(Exception e){
                System.out.println("Debug 5");
                System.out.println("Error in location :"+e.toString());
                System.out.println("Error in location :"+e.getMessage());
             }
        }
    }
};

The error Is with the following line add(mMapField);

Please Help Urgently!

Thank you

Highlighted
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: method cannot be called from event thread

You can't call any blocking operation, like getLocation(), from the event thread.  The GPS stuff should be in a separate thread.

 

Trusted Contributor
Posts: 176
Registered: ‎04-12-2012
My Device: Bold 9780 & Curve 8250
My Carrier: vodacom

Re: method cannot be called from event thread

I tried adding it into another thread but it didnt work?

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: method cannot be called from event thread

Can you be more specific than "didn't work"?