Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI - static fields and remote exceptions  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question that should be simple for some of you to answer - I've looked at this problem quite a bit and I just can't seem to find what's wrong with this code:


I keep getting the following error for DateFactory:
"unreported exception java.rmi.RemoteException; must be caught or declared to be thrown
public static final DateFactory singleton = new DateFactoryImpl ();
The compliler points at the "new".
Any assistance is much appreciated. Thanks.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Erik,
This is a trick question, right? According to your code, the constructor in class "DateFactoryImpl" throws a "RemoteException", therefore, any java code you write that invokes that constructor, needs to handle the possibility that it may throw a "RemoteException".
So in your "DateFactory" interface, you are invoking the "DateFactoryImpl" constructor, but are not handling the "RemoteException" (that may be thrown). Hence the compiler (I assume it is a compiler error -- this wasn't clear to me from your post) is informing you of exactly that fact.
Of-course, your code raises a question with me -- namely, "Why are you creating an instance of the implementation in the interface?
Looks (to me) like you may be having some trouble grasping some RMI concepts. Allow me to suggest the following tutorial (assuming you haven't already seen it):
http://www.dickbaldwin.com/tocadv.htm
[Look for the RMI lessons.]
Hope this helps.
Good Luck,
Avi.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I fully understand RMI fundamentals as well as some of the more advanced bits of RMI.
The problem is that I am attempting to convert someone else's standalone code into RMI code, and the individual used the factory and singleton patterns - both of which I am familiar with, but have not used before with RMI.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I solved the problem my removing the nonsensical static field from the interface, and placing it in the class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!