02-13-2013 02:27 AM
My code below:
try{
Application.getApplication().invokeLater(new Thread(){
public void run(){
if(!checkForAppStop()){
FetchImg thrd=new FetchImg();
thrd.start();
new UploadThread().start(); //start thread
}
else
System.out.println("Application stopped");
}
});
} catch(Exception e){
System.out.println("====Exception: "+e.getMessage());
}
The line highlighted above is giving me the exception " No application instance". Can anyone guide me a solution for this? Thanks a lot.
Solved! Go to Solution.
02-13-2013 04:07 AM
02-13-2013 04:58 AM
Yes I've placed this code in main method. I edited my code to:
Application.getApplication().invokeLater(new Runnable(){
But its still giving me the same exception. What should I do now?
02-13-2013 05:05 AM
02-13-2013 06:33 AM - edited 02-13-2013 06:35 AM
I placed my code in the costructor and it solved my problem. Thanks so much Simon_hain. But I couldn't understand the reason for this. Could you please explain me a bit? Thanks again.
02-13-2013 07:16 AM
02-13-2013 07:24 AM
Simon's explanation is exactly correct. I don't think you can add much to it. I will try to repeat it using different words and perhaps that will help.
When main is executed, there is NO application, there is just a Thread. All main methods create an Application and then use enterEventDisplatcher to get the events running.
When you code Application.getApplication(), you are trying to find the running application, this code goes to the OS and looks for the Application. But in the middle of the Application constructor, you don't have one that the OS knows about. Hence your problem.
Instead of using "Application.getApplication()", in your Application constructor you could actually code "this".
HTH.
02-13-2013 07:34 AM
Thank you simon_hain and peter_strange. That was a wonderful explaination from both of you. I'm glad I'm a part of this forum. Thanks again.