Showing posts with label exception. Show all posts
Showing posts with label exception. Show all posts

Tuesday, July 12, 2011

!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.

This might happen when:
  • sometimes the computer is put for hibernate many times when the eclipse is still working or
  • resources gets called too early before the instance of workspace can be created, or
  • Eclipse did not shutdown correctly.

And eclipse might crash (freeze on splash) with messages like (check workspace\.metadata\.log)

!ENTRY org.eclipse.core.resources 2 10035 2011-07-12 00:32:14.925
!MESSAGE The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes.

It might need to starting everything with a new workspace and then set up all the projects again properly (takes hours to do). Some solutions that can be worth trying :
  1.  remove folder workspace\.metadata\.plugins\org.eclipse.core.resources\.root\.indexes
    and restart Eclipse (Referenced here) . Good to rename rather than delete because some also metioned that there was some other problem after that.
  2.  Go to:
    \.metadata\.plugins\org.eclipse.core.resources and remove the file .snap

    Or remove file : .metadata\.plugins\org.eclipse.core.resources\.projects\<project>\.markers.snap . This is a large snapshot file which Eclipse constantly polls for some projects. (Referenced from here )
  3. The third solution (which worked for me) is  when workbench is restarted/quit, then its need to save the workspace, before existing the workbench then the above message comes.
    Overload the preWindowShellClose() method in your of WorkbenchWindowAdvisor. You can save the workspace by using ResourcesPlugin.getWorkspace().save(...) method. (Sited here)
    import org.eclipse.core.resources.ResourcesPlugin;
    import org.eclipse.core.runtime.CoreException;
    import org.eclipse.ui.application.WorkbenchWindowAdvisor;

    public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

       // other methods...

       @Override
       public boolean preWindowShellClose() {
          try {
             // save the full workspace before quit
             ResourcesPlugin.getWorkspace().save(true, null);
          } catch (final CoreException e) {
             // log exception, if required
          }

          return true;
       }

    }

Tuesday, September 21, 2010

org.eclipse.swt.SWTException: Invalid threadaccess - Two days of follow up and finally its done :

This exception has been nagging up the problem with creation of JFreeChart with the RCP. The reason is that its not allowed to access the UI thread directly; you have to wrap it in something like this: (Source)



new Thread(new Runnable() {
public void run() {
while (true) {
try { Thread.sleep(1000); } catch (Exception e) { }
Display.getDefault().asyncExec(new Runnable() {
public void run() {
... do any work that updates the screen ...
}
}
}
}
}).start();



Ok, but the case is different in our case in the way that we already have actionPerformed method and the update has to be perfomed after getting the value from the database every one second or so. So, in above case, we dont need to create different thread, nor we need code for the timer. So, in our project, this will look something like this:


performDbConnection();
final long f = dataBase.returnNoOfDataset();

// this will only use the current display
try
{
Display.getDefault().asyncExec (new Runnable ()
{
public void run ()
{
series.addOrUpdate(new Millisecond(), f);
}
});
}
catch(Exception E)
{
System.out.println("Exception while updating the chart dynamically: " + e.toString() + "\n");
}