10-04-2012 06:48 AM
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_CEL LSITE)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSI TE);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASS IST)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST );
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUT ONOMOUS)){
blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONO MOUS);
}else{
blackBerryCriteria.setCostAllowed(true);
blackBerryCriteria.setPreferredPowerConsumption(Cr iteria.POWER_USAGE_LOW);
} try {
blackBerryLocationProvider = (BlackBerryLocationProvider) BlackBerryLocationProvider.getInstance(blackBerryC riteria);
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
10-04-2012 10:50 AM
You can't call any blocking operation, like getLocation(), from the event thread. The GPS stuff should be in a separate thread.
10-04-2012 10:53 AM
I tried adding it into another thread but it didnt work?
10-05-2012 09:01 AM
Can you be more specific than "didn't work"?