I am developing Location based J2ME app for my final year, for that I developed a code to access device GPS and by acquiring current place coordinates app will show a plcce on map. The code is as follows:
But when I try to run this code on Nokia E5 or Remote Device Access mobile(Nokia E71).... after clicking on on app, it shows me a message "Unhandled Exception : close application??" but when I run this code on Oracle 3.0.5 emulator.... it perfectly run without showing me any exception.Code:import javax.microedition.lcdui.*; import javax.microedition.location.*; import javax.microedition.midlet.*; public class GmapMidlet extends MIDlet implements CommandListener, LocationListener { Form frm; Command showmap; LocationProvider provider; double latitude = 0, longitude = 0; Coordinates updatedcoordinates, currcoordinates; GmapCanvas Gmap = null; LocationListener listener; //double latitude = 18.962939, longitude = 72.837424; public GmapMidlet() { frm = new Form(""); showmap = new Command("Map", Command.SCREEN, 1); frm.addCommand(showmap); frm.setCommandListener(this); Display.getDisplay(this).setCurrent(frm); //Gmap = new GmapCanvas(this, Double.toString(latitude), Double.toString(longitude)); //Display.getDisplay(this).setCurrent(Gmap); } private void getGPSData() { Thread t = new Thread() { public void run() { Criteria criteria = new Criteria(); criteria.setHorizontalAccuracy(MAX_PRIORITY); criteria.setVerticalAccuracy(MAX_PRIORITY); criteria.setCostAllowed(true); criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH); try { provider = LocationProvider.getInstance(criteria); Location location = provider.getLocation(60); provider.setLocationListener(listener, 30, -1, -1); currcoordinates = location.getQualifiedCoordinates(); if(currcoordinates != null) { latitude = currcoordinates.getLatitude(); longitude = currcoordinates.getLongitude(); } else { showError("GPS is inactive or Location provider is not working properly"); } } catch (LocationException ex) { showError("Problems with location provider! \n" + ex.getMessage()); ex.printStackTrace(); } catch (InterruptedException ex) { showError("Interruption in service... \n" + ex.getMessage()); ex.printStackTrace(); } catch(Exception ex) { ex.printStackTrace(); } } }; t.start(); } public void startApp() { getGPSData(); } public void pauseApp(){} public void destroyApp(boolean unconditional){} public void locationUpdated(LocationProvider Locprovider, Location loc) { if(loc != null && loc.isValid()) { updatedcoordinates = loc.getQualifiedCoordinates(); if(updatedcoordinates != null) { latitude = updatedcoordinates.getLatitude(); longitude = updatedcoordinates.getLongitude(); } else { showError("No valid coordinates found."); } } Gmap.updatedCoordinates(Double.toString(latitude), Double.toString(longitude)); } public void providerStateChanged(LocationProvider Locprovider, int newState) { if(newState == LocationProvider.OUT_OF_SERVICE || newState == LocationProvider.TEMPORARILY_UNAVAILABLE) { showError("Location provider in out of service or temporarily unavailable"); } } void showError(String message) { Alert error = new Alert("GPS Connection Error", message, null, AlertType.ERROR); error.setTimeout(error.getDefaultTimeout()); Display.getDisplay(this).setCurrent(error, frm); } public void commandAction(Command c, Displayable d) { if(c == showmap) { if(currcoordinates != null) { Gmap = new GmapCanvas(this, Double.toString(latitude), Double.toString(longitude)); Display.getDisplay(this).setCurrent(Gmap); } else { showError("Wait.... getting coordinates.."); } } } }
I am not getting whats wrong with this code.... how should I solve this problem????

Reply With Quote


