×

Discussion Board

Results 1 to 6 of 6

Threaded View

  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Mumbai, Maharashtra, India
    Posts
    79

    Unhappy Facing exception during try to running my app on mobile or Remote Access Decvice...

    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:

    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..");
                }
            }
        }
    }
    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.
    I am not getting whats wrong with this code.... how should I solve this problem????
    Last edited by Rahul More; 2013-02-10 at 10:48.

Similar Threads

  1. RNR Failed: Could not access Remote Device (Exception while getting bluetooth name )
    By dayas_90 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2012-04-12, 06:20
  2. access remote mobile file system by bluetooth(OBEX)
    By mohsenkw in forum Mobile Java General
    Replies: 5
    Last Post: 2012-01-02, 12:40
  3. Blue tooth remote access to a mobile phone
    By Zeedzkanik in forum Bluetooth Technology
    Replies: 2
    Last Post: 2009-05-06, 08:53
  4. MMA : Exception during remote invocation
    By brokendove in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-06-06, 05:42

Posting Permissions

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