I am kinda new to BlackBerry OS development, my code is trying to get name of the city while using LocationProvider
after passing Criteria
parameter.
i was following according to this link from RIM itself i tried "JSR-179" and "JSR-179 Extension"
My code is as follows:
"with JSR 179"
public String CurrentLocation()
{
try
{
//LBS(Location Based Service) JSR-179
Criteria criteria = new Criteria();
criteria.isAddressInfoRequired();
criteria.setCostAllowed(false);
criteria.setAddressInfoRequired(true);
criteria.setHorizontalAccuracy(200);
criteria.setVerticalAccuracy(200);
locationProvider = LocationProvider.getInstance(criteria);
location = locationProvider.getLocation(10);
cityName = location.getAddressInfo().getField(AddressInfo.CITY);
}
catch (LocationException le)
{
new Tracer("CurrentLocation() caught LocationException : " + le.getMessage());
le.printStackTrace();
}
catch (InterruptedException ire)
{
new Tracer("CurrentLocation() caught InterruptedException: " + ire.getMessage());
ire.printStackTrace();
}
return cityName;
}
with JSR-179 Extension
public String CurrentLocaiton(){
try
{
BlackBerryCriteria BBCriteria = new BlackBerryCriteria();
BBCriteria.setAddressInfoRequired(ProvideAddressInfoTExt);
BBCriteria.setAltitudeRequired(true);
BBCriteria.setSatelliteInfoRequired(true, true);
BBCriteria.setCostAllowed(true);
BBCriteria.setPreferredPowerConsumption(BlackBerryCriteria.POWER_USAGE_HIGH); //testing for high power
BlackBerryLocationProvider bbLocationProvider
= (BlackBerryLocationProvider)
BlackBerryLocationProvider.getInstance(BBCriteria);
location = bbLocationProvider.getLocation(9000);
QualifiedCoordinates qualCoor = location.getQualifiedCoordinates();
cityName = location.getAddressInfo().getField(AddressInfo.CITY);
}
catch(LocationException le)
{
le.printStackTrace();
System.out.println(le.getMessage());
}
catch(InterruptedException ie)
{
ie.printStackTrace();
System.out.println(ie.getMessage());
}
catch(NullPointerException npe)
{
npe.printStackTrace();
cityName = "Caught Null Pointer";
Dialog.alert(npe.getMessage());
}
return cityName;
}
Am I missing something there or is there something wrong I have been scratching on this issue for hours now.
I tried to catch Null Pointer Exception
from this code snippet as well and if catching from "static void main" then Uncaught Exception: pushModalScreen called by a non-event thread
....
try{
String location = cellLocation.CurrentLocation();
LabelField towerlocationText = new LabelField(towerString + location,
LabelField.FOCUSABLE|LabelField.DEFAULT_POSITION);
add(towerlocationText);
}
catch(NullPointerException npe)
{
npe.printStackTrace();
System.out.println(npe.getMessage());
Dialog.alert(npe.getMessage() + "" + "AddresInfo/LocationProvider/Locaiton gave null pointer exception" );
}
...
tried on BB-9700 BB-9790 Devices as well on Simulator BB-9900
Thanks,