Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 18
Registered: ‎08-06-2009
My Device: Not Specified

GPS / JSR179 mystery exception

I am having trouble with the following code snippet using OS 4.5 on an 8800 device and 8310 device, both were updated from older OS versions.  I use a combination of the Eclipse plugin (1.0 with componant pack 4.5) as an editor and (JDE 4.5) as a builder.

 

The symptom is that an exception is thrown when isEnabled called, yes I know the logic is backwards but it doesn't make the exception any less mysterious. The static initializer is called in the main function due to another static method being called (that does not touch the provider member variable). I enter the method using step in on the JDE with an attached device when I step this one method line an exception is thrown. Could anyone tell me why this might occurr?

 

 static {
criteria = new Criteria();
criteria.setCostAllowed(false);

Thread offEventThread = new Thread(Jsr179GpsImpl.class.getName()) {
public void run() {
try {
provider = LocationProvider.getInstance(criteria);
provider.reset();
} catch (LocationException e) {
e.printStackTrace();
}
}
};

offEventThread.start();
}


public boolean isEnabled() {
return provider == null;
}

 

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS / JSR179 mystery exception

And the exception thrown is?  I'm guessing Null Pointer Exception.

 

I must admit to being very suspicious of using a static initializer as a way of obtaining a LocationProvider, but would like to find out the exception you are seeing before investigating this further.

 

Note that a static object is not necessarily a singleton.  If you want a Singleton, use RuntimeStore. 

Developer
Posts: 18
Registered: ‎08-06-2009
My Device: Not Specified

Re: GPS / JSR179 mystery exception

Its not NullPointerException, its InterruptedException that gets thrown on a boolean comparison. The goal isn't neccessarily to create a singleton but to have a single LocationProvider for all requests for GPS location.  If I understand what your are saying a static variable isn't the same throughout the same process? that would be a bit upsetting.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GPS / JSR179 mystery exception

In a simile process static objects are singletons.  The problem usually comes in when people reference these from other processes.  However an alternate entry point and/or a auto-start up might also qualify as a separate process in the BlackBerry Java world.

 

I presume you are just as confused as I am how a comparison can cause the InterruptedException. 

 

As noted, I'm really not sure about your static initializer.  Can you put a few System.out statements in there (or coded a break point), I'm concerned that it is the provider.reset that is causing the InterruptedException. 

Developer
Posts: 18
Registered: ‎08-06-2009
My Device: Not Specified

Re: GPS / JSR179 mystery exception

[ Edited ]

peter_strange wrote:

In a simile process static objects are singletons.  The problem usually comes in when people reference these from other processes.  However an alternate entry point and/or a auto-start up might also qualify as a separate process in the BlackBerry Java world.


Ack, wow that's a very different model than I know.

 

 

Here is the requested logging, please ask if you need any more.

 

 

static {
criteria = new Criteria();
System.out.println("JSR179 initializer Critera: " + criteria);
criteria.setCostAllowed(false);
System.out.println("JSR179 initializer Critera: " + criteria);

Thread offEventThread = new Thread(Jsr179GpsImpl.class.getName()) {
public void run() {
try {
// Cannot be called on the main event thread, it will throw an error
System.out.println("JSR179 offEventThread Entered Date: " + (new Date()).toString());
System.out.println("JSR179 offEventThread Critera: " + criteria);
provider = LocationProvider.getInstance(criteria);
System.out.println("JSR179 offEventThread LocationProvider" + provider);
provider.reset();
System.out.println("JSR179 offEventThread LocationProvider" + provider);
} catch (LocationException e) {
e.printStackTrace();
System.out.println("JSR179 offEventThread LocationException" + e);
} finally{
System.out.println("JSR179 offEventThread Exiting Date: " + (new Date()).toString());
}
}
};

System.out.println("JSR179 initializer Thread: " + offEventThread);
offEventThread.start();
System.out.println("JSR179 initializer Thread.start() Date: " + (new Date()).toString());
}

public boolean isEnabled() {
//return provider.getState() == LocationProvider.AVAILABLE;
System.out.println("JSR179 " + Thread.currentThread() + " isEnabled LocationProvider:" + provider);
try {
return provider == null;
} catch (Exception e) {
System.out.println("JSR179 " + Thread.currentThread() + " isEnabled catch Exception: " + e.getClass().getName());
throw new RuntimeException(e.getMessage());
}
}
--------------
JSR179 initializer Critera: javax.microedition.location.Criteria@de33d044
JSR179 initializer Critera: javax.microedition.location.Criteria@de33d044
JSR179 initializer Thread: Thread[xxx.gps.Jsr179GpsImpl,5]
JSR179 initializer Thread.start() Date: Fri Aug 21 18:07:04 America/Los_Angeles 2009
JSR179 offEventThread Entered Date: Fri Aug 21 18:07:04 America/Los_Angeles 2009
JSR179 offEventThread Critera: javax.microedition.location.Criteria@de33d044

JSR179 offEventThread LocationProviderjavax.microedition.location.DefaultLocationProvider@97931763
JSR179 offEventThread LocationProviderjavax.microedition.location.DefaultLocationProvider@97931763
JSR179 offEventThread Exiting Date: Fri Aug 21 18:07:04 America/Los_Angeles 2009

JSR179 Thread[Thread-999931904,5] isEnabled LocationProvider:javax.microedition.location.DefaultLocationProvider@97931763

 

 

 

Message Edited by dschultze on 08-21-2009 06:19 PM
Highlighted
Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: GPS / JSR179 mystery exception

Hum, I don't see exception in your log. Does it mean that it happens not inside your try catch?

If it happens inside try/catch can you remoe it and all try/catches in calling methods to make exception unhandled? I'd like to see what is written to the system log (Alt+LGLG or you can dump it to PC via USB running "JDE_HOME\bin\javaloader.exe -u eventlog >device.log" command).

If you can't remove all try/catches could you start new thread and just call isEnabled? Does exception still happens?


--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.