诺基亚设备上的getLocation时出现InstantiationException

时间:2013-04-02 10:51:29

标签: java-me geolocation nokia

诺基亚开发的新手。我正在尝试写一个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);

    }

}

1 个答案:

答案 0 :(得分:0)

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