黑莓 JDE GPS getLocation() LocationException
我需要将 GPS 功能添加到我编写的现有 Blackberry 应用程序中。我编写了一个名为 CurrentLocation 的独立类,并包含一个方法来设置我关心的各种位置变量,方法是将黑莓 GPS 与谷歌的反向地理编码网络服务结合使用。一切都工作得很好,直到我尝试在主应用程序中实例化我的新类。
无论我做什么,我都会收到 LocationException! .getLocation() 不起作用!
这真的让我很困惑,因为如果我在测试 hello world 应用程序中实例化我的类,它就可以正常工作。
实例化类的位置是否有限制?我在之前编写的课程中没有遇到过任何问题。在本例中,我在侦听器中实例化 CurrentLocation 类(因此用户仅在需要时才进行冗长的 GPS 和 Web 调用)。我也尝试过在屏幕中实例化它。我尝试过只删除类并使用方法调用,但这也不起作用。
有什么我完全想念的东西吗?
有一个指向我正在制作的课程的链接,
这是监听器我正在尝试实例化。我处于事件线程中,因为我认为这可能会有所帮助(但无论我是否这样做,我都会得到相同的异常)。
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();
}
}
});
}
};
我在这里缺少什么?
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?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我明白了。显然你不能在 eventThread 中调用 getLocation() (不仅仅是 invokeLater,而是任何侦听器)。所以现在我正在做的是在事件之外的线程中获取坐标,并单独担心谷歌。
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.