×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    JSR 179 Location API - Build Error - Help!

    Hi guys ive just started playing with the location api (jsr 179) for j2me, and cant figure out why theres an error, ive used try and catch around the code....

    Code:
    import javax.microedition.location.*;
    
    try {
    
    			Criteria cr = new Criteria();
    
    			cr.setHorizontalAccuracy(500);
    
    			LocationProvider lp = new LocationProvider.getInstance(cr);
    
    			Location l = lp.getLocation(60);
    
    			Coordinates c = l.getQualifiedCoordinates();
    
    			if (c != null) {
    
    				//do something
    
    			}
    
    		}
    
    		catch (LocationException locExc) {
    
    			System.out.println("Error Getting Location: " + locExc);
    
    		}
    my error message is

    Code:
    enu.java:130: unreported exception java.lang.InterruptedException; must be caught or declared to be thrown
    			Location l = lp.getLocation(60);
    			                           ^
    1 error
    com.sun.kvem.ktools.ExecutionException
    am i doing something very stupid?
    obviously this is only a snip of the code but if you need more just shout! any help would be greatly appreciated,thanks!
    Last edited by fro5tie; 2008-02-05 at 17:08.

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,192

    Re: JSR 179 Location API - Build Error - Help!

    getLocation() can throw
    LocationException - if the location couldn't be retrieved or if the timeout period expired
    java.lang.InterruptedException - if the operation is interrupted by calling reset() from another thread
    java.lang.SecurityException - if the calling application does not have a permission to query the location information
    java.lang.IllegalArgumentException - if the timeout = 0 or timeout < -1
    In your code you only catch LocationException...

    Hartti

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    4

    Re: JSR 179 Location API - Build Error (cannot find symbol)

    Got it sorted now yes thanks just needed to throw just Exception, thanks silly me

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    46

    Re: JSR 179 Location API - Build Error (cannot find symbol)

    It would be nice if the actual solution would have been posted here. This topic only gives me small hints now, and I can see that one particular coder has solved his/her problem.

    I am having the same problems as described in the first post. I need to make a throwable object or something?
    Any help would be great!

    Thanks in advance.

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: JSR 179 Location API - Build Error (cannot find symbol)

    When you invoke a method that can throw exceptions that are not subclasses of RuntimeException, then your code must either catch that exception, or the enclosing method must also declare itself as throwing the same exception.

    For example: Connector.open() throws IOException, so:

    PHP Code:
    // This is NOT OK
    public InputStream openServerConnection() {
        return 
    Connector.open(SERVER_URL);
    }

    // This IS OK
    public InputStream openServerConnection() throws IOException {
        return 
    Connector.open(SERVER_URL);
    }

    // This IS OK (but bad practice!)
    public InputStream openServerConnection() {
        try {
            return 
    Connector.open(SERVER_URL);
        } catch (
    IOException e) {
            return 
    null;
        }

    The latter of these is bad practice, because the returned null will probably cause a NullPointerException, which will make the problem much harder to identify than the original IOException (which contained information about the actual problem).

    Graham.

Similar Threads

  1. GoogleIt
    By deepika.mangla in forum Symbian
    Replies: 5
    Last Post: 2011-05-28, 11:04
  2. Location API (JSR 179) without GPS..
    By d33 in forum Mobile Java General
    Replies: 21
    Last Post: 2008-08-01, 13:51
  3. Replies: 7
    Last Post: 2008-02-08, 12:02
  4. Location API JSR 179
    By scarasimon in forum Series 40 & S60 Platform Feedback Archive
    Replies: 1
    Last Post: 2007-11-15, 18:13
  5. illegal use of abstract class error...
    By kannabiran.krish in forum Symbian
    Replies: 7
    Last Post: 2007-08-17, 10:11

Posting Permissions

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