sebap123 Opublikowano 31 Sierpnia 2009 Zgłoś Opublikowano 31 Sierpnia 2009 Witam Napisałem nie dawno aplikacje, która wykorzystuje nadajnik GPS w telefonie. W programie wszystko jest ok ale gdy uruchomie emulator pojawia sie jeden z błędów: java.lang.IllegalStateExceptionlub też java.lang.NullPointerExceptionten pierwszy juz jakos udało mi się wyłączyc przez uzycie catch`a ale ten drugi nie daje rady. A i co jeszcze ważniejsze program napisałem przy użyciu MIDP-2.1 i CLDC-1.1 bo inne ustawienia wywołuja bledy, a program (plik jar) nie chce sie uruchomic na telefonie (nokia N95). Pisze, że telefon jest niekompatybilny. Poniżej jest kod programu może po prostu jest jakiś glupi bląd. import javax.microedition.midlet.*;import javax.microedition.location.*;import javax.microedition.lcdui.*;import java.lang.InterruptedException.*;import java.lang.Double.*;/** * @author Sebastian */public class GPS extends MIDlet implements CommandListener{private Criteria cr;private LocationProvider provider;private Display dp;private Alert alert;private Location location;private Form dane;private StringItem lo, la, t1, t2;private List menu;private Command oKCommand;public GPS(){// Criteria can be used to filter which GPS device to use.Criteria criteria = new Criteria();criteria.setCostAllowed(true);criteria.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);oKCommand = new Command("Wybierz", Command.OK, 0);menu = new List("Menu", List.IMPLICIT); menu.append("GPS",null); menu.addCommand(oKCommand); menu.setCommandListener(this);try{// Get a location provider based on the aforementioned criteria.LocationProvider provider = LocationProvider.getInstance(criteria);Location location = provider.getLocation(180);Coordinates coordinates = location.getQualifiedCoordinates();if (coordinates != null) { // Get the latitude and longitude of the coordinates. double latitude = coordinates.getLatitude(); double longitude = coordinates.getLongitude(); dane = new Form("Dane GPS"); String la = Double.toString(latitude); String lo = Double.toString(longitude); Spacer odstep = new Spacer(dane.getWidth(), 5); t1 = new StringItem(null, "szerokosć:"); t2 = new StringItem(null, "długość:"); dane.append(t1); dane.append(odstep); dane.append(la); dane.append(odstep); dane.append(t2); dane.append(odstep); dane.append(lo);} else { alert = new Alert("Brak współrzędnych", null, null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); dp.setCurrent(alert);}}catch(LocationException e0){ System.out.println("Błąd"); }catch (java.lang.InterruptedException e1){ alert = new Alert("Błąd nr1", null, null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); dp.setCurrent(alert);}catch (java.lang.SecurityException e2){ alert = new Alert("Błąd nr2", null, null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); dp.setCurrent(alert);}catch (java.lang.IllegalArgumentException e3){ alert = new Alert("Błąd nr3", null, null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); dp.setCurrent(alert);}catch (IllegalStateException e4){ alert = new Alert("Błąd nr4", null, null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); dp.setCurrent(alert);}// Get the coordinates of the current location.} public void startApp() { dp.setCurrent(menu); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c,Displayable d){ if (c == List.SELECT_COMMAND && d == menu) { int indeks = menu.getSelectedIndex(); String akcja = menu.getString(indeks); if (akcja.equals("GPS")) { dp.setCurrent(dane); } }}}Bardzo prosze o pomoc. Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
Gh0st7 Opublikowano 17 Września 2009 Zgłoś Opublikowano 17 Września 2009 1. Zmien platforme na MIDP 2.0, CLDC 1.1 zostaje, sprawdz na telefonie. 2. Pokazales tylko fragmenty bledow, nie wiadomo w ktorej linii wystepuje NullPointerException i czego sie tyczy.. Zgadywac chyba nie bedziemy. Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...