Question

New to Nokia development. I am trying to write a hello world for get GPS coordinates of my current location. What am I doing wrong here ?

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);

    }

}
Was it helpful?

Solution

In the application descriptor I had UpdateJourney as the MIDlet, I changed it to HomeScreen and it worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top