views:

359

answers:

1

I need to add GPS functionality to an existing Blackberry Application that I've written. I write a stand alone class called CurrentLocation, and include a method to set the various location variables I care about by using the blackberry GPS in conjunction with google's reverse geocoding webservices. Everything is working beautifully, that is, until I try to instantiate my new class in my main application.

No matter what I do, I get a LocationException! .getLocation() doesn't work!

It really confuses me, because if I instantiate my class in a test hello world app, it works just fine.

Are there limits to where you can instantiate classes? I've not encountered any with previous classes I've written. In this case, I'm instantiating my CurrentLocation class in a listener (so the user only makes the lengthy gps and web calls when they want to). I've tried instantiating it in screens, as well. I've tried just gutting the class and using the method call, but that doesn't work either.

Is there something I'm missing entirely here?

http://pastie.org/639545

There's a link to the class I'm making,

And here's the listener I"m trying to instantiate from. I'm in an event thread because I thought it might help (but I get the same exception whether or not I do this).

FieldChangeListener listenerGPS = new FieldChangeListener() {
     public void fieldChanged(Field field, int context) {
      UiApplication.getUiApplication().invokeLater(new Runnable() {
       public void run() {
        CurrentLocation loc = new CurrentLocation();
        if (loc != null){
         country = loc.getCountry();
         city = loc.getCity();
         state = loc.getState();
         road = loc.getRoad();
         zip = loc.getZip();
        }
        }

      });

     }
    };

What am I missing here?

+2  A: 

Okay, I got it. Apparently you can't call getLocation() in the eventThread (not just invokeLater, but any listener). So now what I'm doing is getting the coordinates in a thread outside of the event, and worrying about google separately.

Jenny