我正在开发一个应用程序,试图获取当前位置。但我收到错误“无法从事件线程调用 getLocation() 方法”,即使我创建了一个新线程。谁能帮帮我吗?
这是我的代码
Thread t = new MyThread();
t.run();
这是 MyThread 类的 run 函数:
try
{
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(500);
LocationProvider lp = LocationProvider.getInstance(cr);
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates();
if (c != null)
{
double longitude = c.getLongitude();
double latitude = c.getLatitude();
Dialog.alert("latitude:"+latitude);
Dialog.alert("longitude:"+longitude);
}
}catch(Exception e){
Dialog.alert(e.getMessage());
}
最佳答案
您不能通过调用 run() 方法来启动线程。您可以通过调用 start() 方法来启动线程。
关于blackberry - "getLocation() method cannot be called from event thread",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6013289/