Note that there are some explanatory texts on larger screens.

plurals
  1. PONull pointer exception for city name when using Location API with LBS JSR-179 and JSR-179 Extended
    primarykey
    data
    text
    <p>I am kinda new to BlackBerry OS development, my code is trying to get name of the city while using <code>LocationProvider</code> after passing <code>Criteria</code> parameter. i was following according to this <a href="http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949" rel="nofollow">link</a> from RIM itself i tried "JSR-179" and "JSR-179 Extension" My code is as follows:</p> <p>"with JSR 179"</p> <pre><code>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; } </code></pre> <p>with JSR-179 Extension</p> <pre><code>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; } </code></pre> <p>Am I missing something there or is there something wrong I have been scratching on this issue for hours now. I tried to catch <code>Null Pointer Exception</code> from this code snippet as well and if catching from "static void main" then <code>Uncaught Exception: pushModalScreen called by a non-event thread</code></p> <pre><code> .... 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" ); } ... </code></pre> <p><em>tried on BB-9700 BB-9790 Devices</em> as well on <em>Simulator BB-9900</em></p> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload