• Post Reply Bookmark Topic Watch Topic
  • New Topic

Making real time digital clock using RCP.  RSS feed

 
rajeev wadhwani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI ,
I am new to Rich Client Platform. I want to make a real time clock .So , for that i think i have to refresh the view every second.
So ,for that i have used the following code snippet for view :

But by doing this i am getting the following error:
Exception in thread "Thread-3" org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.SWT.error(SWT.java:3666)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:355)
at org.eclipse.swt.widgets.Control.redraw(Control.java:1986)
at testmail.View$1ReTry.run(View.java:92)
at java.lang.Thread.run(Unknown Source)

Can any one please help in solving this problem .

 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, welcome to Java Ranch!
You should UseCodeTags when providing source code, stack traces, xml content, etc., as it makes it a lot easier to read. You should edit your post and add code tags around your code snippet. If your actual code has no indentation, fix that too

Next, why are you calling parent2.dispose() from within your ReTry class? What will that call do?

Next, how accurate do you think your real time clock will be give the logic you're using?

In any case, it seems your question really has nothing to do with creating a real time digital clock but instead has to do with getting an exception when trying to start a utility thread from within your Rich Client Platform application - so your topic subject is not very good. You should fix it as well.

Good luck.
 
rajeev wadhwani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Mark,
From next time i will make sure that i will use proper indentation while posting the code.
Regarding logic , i have to use thread for refreshing the view every second ,
and inside run method i have to call parent2 .reDraw() , which will be called after each second as i have called Thread.sleep(1000).
As far as i can see the logic is correct .

 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rajeev wadhwani wrote:HI Mark,
From next time i will make sure that i will use proper indentation while posting the code.
Don't wait for the next time. You can fix it now. Edit your post by clicking on the edit button and add the code tags.
rajeev wadhwani wrote:Regarding logic , i have to use thread for refreshing the view every second ,
and inside run method i have to call parent2 .reDraw() , which will be called after each second as i have called Thread.sleep(1000).
As far as i can see the logic is correct .


Did you mean parent2.redraw()?

In any case, I asked why you were calling parent2.dispose(). Look up the javadoc on that method and read about what it does. Are you sure you want to be calling it? Please explain why.



 
rajeev wadhwani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark ,

You are right , parent2.dispose() should not be used . I have updated the code snippet ,but still i am getting the same error.

 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see two problems right off the bat. First, have a look at your run() method. Let's follow the logic through. You have a method named createPartControl(). At the end of this method you create a Thread to do something. What is it you want this thread to do?
What is it doing? Hint: How many times will it sleep? What will it do then?

Next, what happens when the createPartControl() method is finished? Specifically, what happens to the variable t?

If you still don't see it, answer this: How many times will parent2.redraw() be called while your application is running?
 
rajeev wadhwani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Mark,
You were right .I have to use endless while loop inside run method.
Below is the snippet for the run method that did the trick for me .



Thanks a lot for useful suggestions .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!