×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    22

    [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)
    {
    }

    }
    }




    }

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: what is the wrong in this code snippet?

    I am not sure about your code to fetch location. Please read this


    Just merge that class with your application and do method communication between class. Let us know yet if you face any problem.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    22

    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.

Similar Threads

  1. Replies: 3
    Last Post: 2008-11-06, 17:19
  2. Replies: 4
    Last Post: 2008-10-28, 16:12
  3. Operator logo doesn't get saved. Wrong operator code?
    By Nokia_Archive in forum Smart Messaging
    Replies: 3
    Last Post: 2006-10-05, 11:30
  4. what is wrong with the code?
    By naneziris in forum Mobile Java General
    Replies: 1
    Last Post: 2006-06-01, 04:41
  5. Progress bars: what's wrong with my code?
    By bobline in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2003-05-29, 18:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×