Recently, I've noticed that for any BlackBerry project I run, the JDE throws an error with message
开发者_运维知识库Exception thrown: no application instance...
I've even checked with a sample hello world project, which ends up with the same problem.
I did run clean.bat file, erase file system etc. work arounds to clear the archives, but no luck till now. Could someone please guide me correctly what should be the fix for this?
I'm assuming the full exception is: "IllegalStateException: no application instance". Since you didn't give us many details of your code, I'll just talk about where I've commonly run into this Exception.
This is commonly caused by trying to get an application instance before you have called the Application's constructor. For example the following code will create that error:
public class HelloWorld extends UiApplication
{
public HelloWorld(){
pushScreen(new HelloWorldScreenBlank());
}
public static void main(String[] args) {
Application app = Application.getApplication();
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
}
}
This code produces the following console code:
llegalStateException
no application instance
net_rim_cldc-8(4B84A78F)
Application
getApplication
0x2EFA
HW_5$2e0(4D1A6F55)
HelloWorld
main
0x167
But the following code doesn't produce the exception:
public class HelloWorld extends UiApplication
{
public HelloWorld(){
Application app = Application.getApplication();
pushScreen(new HelloWorldScreenBlank());
}
public static void main(String[] args) {
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
}
}
This works because the Application instance is instantiated inside the constructor for the UiApplication object. Were as in the previous code we were trying to get the instance before an Application object existed.
I've commonly run into this trying to startup GPS from main() or in a static block. But there are a few classes which implicitly call getApplicaiton, so if you aren't explicitly calling getApplication then maybe one the API calls your making is. I would try to move code out of main and into your Application's constructor if you can.
Here is a Google search which will produce a list of classes from the 6.0 API which produce this exception:
throws IllegalStateException Blackberry site:www.blackberry.com/developers/docs/6.0.0api
精彩评论