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

Reply
Regular Contributor
heather_1
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

NullPointerException at getLocation() while debugging on device

Hi all,

 

I am attempting to debug my app on a device. Everything works on the simulator, but when I try to run it on a BB 9360 running a 5.0.975 OS, I get a NullPointerException at lp.getLocation(60) (right after the first "try"). Here is my code:

 

	Criteria cr;
	Location l = null;
	LocationProvider lp;
	Coordinates c = new Coordinates(0, 0, 0);
    public LocationHelper() throws LocationException
    {

		cr = new Criteria();

		cr.setHorizontalAccuracy(60);

		//cr.setVerticalAccuracy(60);

		cr.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);

		lp = LocationProvider.getInstance(cr);

		try{
        l = lp.getLocation(60);

        c = l.getQualifiedCoordinates();
      
		}catch (LocationException ex) {

			ex.printStackTrace();

		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		
        try
        {
            LocationProvider provider = LocationProvider.getInstance(cr);
            provider.setLocationListener(new LocationHelperListener(), 10, -1, -1);
        }
        catch ( LocationException lex )
        {
            return;
        }

 Any suggestions?

Please use plain text.
Regular Contributor
heather_1
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: NullPointerException at getLocation() while debugging on device

I found the problem...the GPS was not turned on in the device

Please use plain text.
Developer
RexDoug
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: NullPointerException at getLocation() while debugging on device

You might also want to tighten up this code a little bit.

 

 l = lp.getLocation(60);

c = l.getQualifiedCoordinates();

 

Here is why: getLocation() may return null (as you already found out). YOu should be checking for this and raising some type of user alert.


 

Please use plain text.
Contributor
ali_irawan
Posts: 14
Registered: ‎05-18-2011
My Device: 9300, 9700
My Carrier: T-Mobile

Re: NullPointerException at getLocation() while debugging on device

l = lp.getLocation(60);

if ( l!=null && l.isValid()){
c = l.getQualifiedCoordinates();
}

how bout tyring this
Until you spread your wings, You will have no idea how far you can fly
Please use plain text.
Regular Contributor
heather_1
Posts: 83
Registered: ‎05-24-2011
My Device: Storm 9550
My Carrier: XXX

Re: NullPointerException at getLocation() while debugging on device

I'll do that! Thanks.

Please use plain text.