eforr: In all seriousness, you need to learn Java. Right now you're just blindly moving code around - and doing so in the JDE, which isn't helping anything (the Eclipse IDE will underline undefined variables and flag incomplete interface implementations).
The errors that you mentioned were all trivial to find and resolve. You're not exactly starting with HelloWorld here, so if you plan on continuing with development you need to get a good book or two ("Thinking in Java" is great), hang out on some Java forums, and get up to speed on the language itself. Otherwise, there will simply be no end to the errors.
Now, the LocationListenerImpl implements LocationListener and needs to implement both methods from that interface; it only implemented one. Further, many of the variables were not declared. Basic stuff.
I don't know if the code now *works* but it compiles.
Code:
class G extends MainScreen
{
private int _interval = -1;
public G()
{
super();
// Set criteria for selecting a location provider:
Criteria cr= new Criteria();
cr.setCostAllowed(true);
cr.setPreferredResponseTime(60);
cr.setHorizontalAccuracy(5000);
cr.setVerticalAccuracy(5000);
cr.setAltitudeRequired(true);
cr.isSpeedAndCourseRequired();
cr.isAddressInfoRequired();
add(new RichTextField("Getting Coordinates...."));
try{
LocationProvider lp = LocationProvider.getInstance(cr);
if( lp!=null ){
// Must declare "_interval" somewhere. I did this above. See Javadocs
// for an explanation of what this parameter does.
lp.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);
}
add(new RichTextField("I'm in try statement"));
add(new RichTextField("other side"));
//System.out.println("Lon" + longitude + " Lat "+ latitude + " course "+course+" speed "+speed+" timestamp "+timestamp);
}
catch(LocationException le)
{
add(new RichTextField("Location exception "+le));
}
}
private class LocationListenerImpl implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
if(location.isValid()) {
// These needed to be declared. Don't have to be declared right here,
// but they need to be declared *somewhere* that's visible from here.
double longitude = location.getQualifiedCoordinates().getLongitude();
double latitude = location.getQualifiedCoordinates().getLatitude();
double altitude = location.getQualifiedCoordinates().getAltitude();
float speed = location.getSpeed(); }
}
public void providerStateChanged(LocationProvider provider, int newState) {
// MUST implement this. Should probably do something useful with it as well.
}
}
}