Witam
Juz jakiś czas pisze midlet (a raczej jego serce), który korzysta z wbudowanego w telefon GPS. Mam jednak mały problem bo caly czas pokazuje mi dwa błędy w czasie pracy na emulatorze (korzystam w pracy z NetBeans):
java.lang.IllegalStateException
lub taki:
java.lang.NullPointerException
Ale normalnie pojawia się okienko startowe (znaczy się pytanie aplikacji o możliwość używania odbiornika GPS.
Jest jednak drugi poważniejszy problem. Program nie chce się zainstalowac na telefonie. Korzystam z ustawień: MIDP-2.1 i CLDC-1.1, a chce to zainstalować na telefonie Nokia N95. W czasie instalacji pojawia się kounikat, że telefon jest niekompatybilny.
Bardzo bym prosil o pomoc.
Poniżej jeszcze kod, który może pomoże i przyspieszy diagnoze błędu:
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);
}
}
}}
Będę bardzo wdzięczny za pomoc.