Troubleshooting guide

209
14: Using location information
}
};
// Cache the close menu item for reuse.
private MenuItem _close = new MenuItem(_resources, GPSDEMO_MENUITEM_CLOSE, 110, 10) {
public void run() {
System.exit(0);
}
};
/* Invokes the Location API with the default criteria.
*/
private boolean startLocationUpdate() {
boolean retval = false;
try {
_locationProvider = LocationProvider.getInstance(null);
if ( _locationProvider == null ) {
// We would like to display a dialog box indicating that GPS isn’t
supported, but because
// the event-dispatcher thread hasn’t been started yet, modal screens cannot
be pushed onto
// the display stack. So delay this operation until the event-dispatcher
thread is running
// by asking it to invoke the following Runnable object as soon as it can.
Runnable showGpsUnsupportedDialog = new Runnable() {
public void run() {
Dialog.alert(“GPS is not supported on this platform, exiting...”);
System.exit( 1 );
}
};
invokeLater( showGpsUnsupportedDialog ); // ask event-dispatcher thread to
display dialog ASAP
} else {
// A single listener can be associated with a provider,
// and unsetting it involves the same call but with null,
// so there is no need to cache the listener instance.
// Request an update every second.
_locationProvider.setLocationListener(new LocationListenerImpl(),
_interval, 1, 1);
retval = true;
}
} catch (LocationException le) {
System.err.println(“Failed to add a location listener. Exiting...”);
System.err.println(le);
System.exit(0);
}
return retval;
}
/**
* Invokes a separate thread used to send data to the server
*/
private void startServerConnectionThread()
{
_serverConnectThread = new ServerConnectThread(_hostName);
_serverConnectThread.start();