This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

ClassCastException Problem  RSS feed

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a business interface for data access: For example

In RMI, I have the same interface, say

Then I try to connect client across the network when server running and I try and cast and use the data layer interface

I get following error:
"java.lang.ClassCastException: Proxy cannot be cast to suncertify.db.HotelReservationDB"
Any reason why I can't cast, even though interfaces are same apart from remote exception?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Look, HotelReservationDB Interface is totally different of HotelReservationDBRemote interface.
You cannot to cast like this: "(HotelReservationDB)hotelReservation". To do it, is the same you want to transform "orange" in "apple". You can't to do this. Think about it. What do you really want to do?
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers, thanks. Sorry, if I give impression I'm clueless, I was hoping to have cleaner code when calling the direct or network client connection by having the 1 interface reference. Is the only approach to this referencing to use a separate reference for each of the direct client and network client connection? Thanks very much for kind replies.
 
Bartender
Posts: 2292
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Mark!

Cheers, thanks. Sorry, if I give impression I'm clueless



Champion, we are all here to discuss and help each other. So... no need to worry, partner! We are glad to help and discuss

Now, please take a look at this sample code provided by my good buddy Roel to see if it helps.
 
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Roberto Perillo wrote:Now, please take a look at this sample code provided by my good buddy Roel to see if it helps.


That's what I have been dreaming about for many weeks and months: being referenced by the Great Roberto
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hahahaha

That's my good friend Roel!
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers, thanks for all your help. Just wondering 1 final point, in my set-up I have, package-wise say:
BusinessService and LocalBusinessServiceImpl both in the db package.
BusinessRemote and NetworkBusinessServiceImpl in the remote package.
How can I justify throwing the remoteException for the methods in the BusinessService interface while these classes are supposed to be accessed locally? I hope one understands that I'm asking.
Or would I be better packaging the application differently to support throwing the RemoteException from the methods?
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, for everything related to the business/services layer, I'd create a package called business or services.

Now, about the exception, I see your point... but if a method is defined in an interface and has the RemoteException in its throws clause, it means that it can throw it. The implementation doesn't need to include it in its throws clause if it won't be thrown.
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

It is also shown in the provided: the method in the LocalBusinessServiceImpl is not throwing a RemoteException.

Regarding your package structure. I defined 3 packages: service (contains my business interface + service-exceptions), direct (for the local business implementations) and rmi (contains all classes to do the RMI-stuff).

Kind regards,
Roel
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!