【问题标题】:"getLocation() method cannot be called from event thread"“无法从事件线程调用 getLocation() 方法”
【发布时间】:2011-05-19 02:40:39
【问题描述】:

我正在开发一个试图获取当前位置的应用程序。但是即使我创建了一个新线程,我也会收到错误“无法从事件线程调用 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());

    }

【问题讨论】:

    标签: blackberry


    【解决方案1】:

    您不会通过调用 run() 方法来启动线程。你通过调用 start() 方法来启动一个线程。

    【讨论】:

    • 即使我使用 start() 方法,我也得到了同样的错误。有什么想法吗??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-03
    • 2016-05-06
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多