0

诺基亚开发的新手。我正在尝试编写一个 hello world 来获取我当前位置的 GPS 坐标。我在这里做错了什么?

public class HomeScreen extends MIDlet  {

    public HomeScreen() {
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    }

    protected void pauseApp() {
    }

    protected void startApp() throws MIDletStateChangeException {
        Displayable current = Display.getDisplay(this).getCurrent() ;
        if (current == null) {
            UpdateJourney updateJourney = new UpdateJourney(this) ;
            Display.getDisplay(this).setCurrent(updateJourney) ;
        }
    }

}

public class UpdateJourney extends Form implements CommandListener, Runnable {
    private LocationProvider myLocation;
    private Criteria myCriteria;
    private Location myCurrentLocation;

    private HomeScreen helloScreen;
    private Command exitCommand;

    private Thread getLocationThread = new Thread(this);;

    public UpdateJourney(HomeScreen helloScreen) {
        super("Taxeeta");

        StringItem helloText = new StringItem("", "Taxeeta");
        super.append(helloText);
        this.helloScreen = helloScreen;
        getLocationThread.start();
    }

    public double getMyLatitude() {
        return myCurrentLocation.getQualifiedCoordinates().getLatitude();
    }

    public double getMyLongitude() {
        return myCurrentLocation.getQualifiedCoordinates().getLongitude();
    }

    public void commandAction(Command command, Displayable arg1) {
        if (command == exitCommand) {
            helloScreen.notifyDestroyed();
        }
    }

    public void run() {
        myCriteria = new Criteria();
        myCriteria.setHorizontalAccuracy(500);
        try {
            myLocation = LocationProvider.getInstance(myCriteria);
            myCurrentLocation = myLocation.getLocation(60);
        } catch (LocationException e) {
            e.printStackTrace();
            System.out
                    .println("Error : Unable to initialize location provider");
            return;
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("Error: Waited enough for location to return");
            return;
        }
        System.out.println("Location returned Lat:"
                + myCurrentLocation.getQualifiedCoordinates().getLatitude()
                + " Lng:"
                + myCurrentLocation.getQualifiedCoordinates().getLongitude());
        exitCommand = new Command("Location returned Lat:"
                + myCurrentLocation.getQualifiedCoordinates().getLatitude()
                + " Lng:"
                + myCurrentLocation.getQualifiedCoordinates().getLongitude(),
                Command.EXIT, 1);
        addCommand(exitCommand);
        setCommandListener(this);

    }

}
4

1 回答 1

0

在应用程序描述符中,我将 UpdateJourney 作为 MIDlet,我将其更改为 HomeScreen 并且它可以工作。

于 2013-04-02T11:20:10.463 回答