• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

RMI - static fields and remote exceptions

 
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.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • 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.
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic