私はBlackBerryOS開発に少し慣れていません。私のコードは、パラメーターLocationProvider
を渡した後に使用しているときに都市の名前を取得しようとしていCriteria
ます。私はRIM自体からこのリンクに従ってフォローしていました。「JSR-179」と「JSR-179Extension」を試しました。私のコードは次のとおりです。
「JSR179付き」
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;
}
JSR-179エクステンション付き
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;
}
私はそこに何かが欠けているのでしょうか、それとも私が何時間もこの問題に引っかいてきた何かが間違っているのでしょうか。このコードスニペットからもキャッチしようとしましたNull Pointer Exception
が、「staticvoidmain」からキャッチする場合は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" );
}
...
シミュレーターBB-9900でもBB-9700BB-9790デバイスで試してみました
ありがとう、