[moved] what is the wrong in this code snippet?
Helo. i need help about this code. i'll be be made.It doesn't work. i couldn't find the problem. In this code:i create a canvas class.i show the object of canvas on screen. Then the location informations(GPS) uptade via upDate class,but the informations about gps location doesn't show on canvas object.
public class canvasMidlet extends MIDlet implements LocationListener {
private Display display;
private Form form;
private Command cmdExit,cmdOK;
private StringItem si;
showInfo can;
Location loc;
LocationProvider provider;
Coordinates coor;
Criteria cr;
public canvasMidlet()
{
display = Display.getDisplay(this);
}
public class showInfo extends Canvas implements CommandListener
{
String messageinfo="";
public showInfo()
{
cmdExit = new Command("Exit",Command.EXIT,5);
cmdOK = new Command("OK",Command.OK,1);
addCommand(cmdOK);
addCommand(cmdExit);
setCommandListener(this);
setTitle("GPS Information");
}
public void setMessage(String s)
{
messageinfo=s;
}
public void paint(Graphics g)
{
g.setColor(255);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(255,255,255);
g.drawString(messageinfo,5,5,0);
}
public void commandAction(Command c, Displayable d)
{
if (c == cmdOK){
Connection();
} else if (c == cmdExit) {
//destroyApp(false);
notifyDestroyed();
}
}
}
public void Connection ()
{
try
{
cr=new Criteria();
cr.setHorizontalAccuracy(25);
cr.setSpeedAndCourseRequired(true);
cr.setAltitudeRequired(true);
cr.setPreferredResponseTime(5000);
provider=LocationProvider.getInstance(cr);
if(provider!=null)
//finf.append("\n\nBağlantı sağlandı.......");
provider.setLocationListener(this,5,10,10);
}
catch(LocationException ex)
{
Alert a=new Alert("ERROR :");
a.setString(ex.toString());a.setTimeout(Alert.FOREVER);
a.setTimeout(Alert.FOREVER);
}
}
public void startApp() {
can=new showInfo();
display.setCurrent(can);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void locationUpdated(LocationProvider provider, Location location)
{
upDate t=new upDate(can);
t.start();
}
public void providerStateChanged(LocationProvider provider, int newState) {
}
/////////////////////////
//THREADDDDDDDDDDDDDD
public class upDate extends Thread
{
showInfo canvas;
public upDate(showInfo c)
{
canvas=c;
}
public void run()
{
try
{
// loc=provider.getLocation(-1);
if(loc.isValid())
{
// finf.deleteAll();
// String s="";
coor=loc.getQualifiedCoordinates();
double en=coor.getLatitude();
double boy=coor.getLongitude();
float yon=loc.getCourse();
double hiz=loc.getSpeed();
long time=loc.getTimestamp();
String enlem,boylam;
enlem=coor.convert(coor.getLatitude(),1);
boylam=coor.convert(coor.getLongitude(),1);
String s="";
s="Enlem : "+enlem+"\nBoylam : "+boylam+
"\nYön : "+yon+"\nHız : "+hiz+"\nZaman : "+time;
canvas.setMessage(s);
canvas.repaint();
}
}
catch(Exception ex)
{
}
}
}
}
Re: what is the wrong in this code snippet?
I am not sure about your code to fetch location. Please [URL="http://wiki.forum.nokia.com/index.php/Java_ME_Location_API"]read this[/URL]
Just merge that class with your application and do method communication between class. Let us know yet if you face any problem.
Re: what is the wrong in this code snippet?
this code is running if i use Form in the application. My problem is:when i use Canvas class to show information it oesn't show informations.Wen i use Form instead of Canvas(for example Form finf=new Form("Information");),ilocation informations shows on the screen.There is a problem about Canvas,but i couldn't find it.