aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Naming.lookUp throws a ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Naming.lookUp throws a ClassCastException" Watch "Naming.lookUp throws a ClassCastException" New topic
Author

Naming.lookUp throws a ClassCastException

Oladeji Oluwasayo
Ranch Hand

Joined: Sep 10, 2010
Posts: 101

I'm still stuck with this bug. Its throwing a ClassCastException <MyRemoteObject_Stub> cannot be cast to <MyRemoteObject>
when I invoke Naming.lookUp(url) to get the remote object from the registry.
What do I do? I've tried virtually everything. Maybe I shouldn't have used RMI. I was very familiar with traditional sockets.


OCPJP 6, OCMJD 6
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2267
    
    3

Well champ, can you show us a small piece of your code? It will be sort of hard to say what's going on without looking at it.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Does your code has the correct structure (implementing the appropriate interfaces etc.)? Here you can find an example.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Oladeji Oluwasayo
Ranch Hand

Joined: Sep 10, 2010
Posts: 101

Thanks bartender, I've fixed the class cast issue and now the database gets across the wirw to the client side but there's another problem. Whenever i invoke a method like generateUniqueID(), the correct value is gotten at the client side but when I invoke the getInventory() method (which returns a Map<Integer, HotelRecord>), an empty Map is gotten on the client side and my hotel table controller relies heavily on this method to populate the JTable display, hence, a blank table. I have rescheduled because of thish issue. (the deadline is crazy, I thought I would be having a year, now school exam starts next week, I also have a digital circuit project to defend this week). How can I quickly get around this bug?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

Are you using a thin or thick client approach? Anyway your map with <Integer, HotelRecord> pairs should not go to the client, because that makes no sense.

Sounds to me your application is quite buggy and you are fixing one bug and another is already there. Maybe you should re-evaluate your whole solution and approach. Your previous topic had as title "URLyBird, almost done, but some lil' probs here", the things you describe in these topics are not little problems but major issues!
Oladeji Oluwasayo
Ranch Hand

Joined: Sep 10, 2010
Posts: 101

I think I have the proper structure for rmi commiunication. A remote interface extending remote and serializable, an implementation class extending unicast remote object, exported using registry's rebind method, fetched at the other side using naming.lookup(). The class cast exception was me casting to the wrong type, sorry for raising uneeded alarm on that I used the same client for stand-alone and network and for stand-alone, its working fine. The map is a return value of one of the methods in the database. It only returns a copy of the actual map in the database not the real one (of course I know the implications of what you thought there Roel). It is the database that I exported with a wrapper (similar to exporting a factory that houses a single database -- my methods would then not be forced to include the throws clause for remote exeption, crappy shortcut there eh?). My approach is quite similar to that of Andrew Munkhouse in his SCJD book only that I extended the DB interface to add a few convinience methods. Data class passed locking Roberto's locking (with a hundred thousand threads, i was just having fun with threads ). Classes in the diferent packages are loosely coupled (so I can completely wipe out all the netwok stuffs without touching the GUI code). MVC employed in the JTable. It is only in the connectToDataSource(AppMode mode, Configuration config) that the GUI code obtains a reference of the database based on the application mode (local or network) and the rest of the system is not aware whether the database is local or remote.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5545
    
  13

That sounds indeed as a nice setup of your solution, but having your getInventory-method return an empty map when in networked mode is a big issue and a bit strange that you discovered this at the point you wanted to submit. I think you would have discovered this a whole lot faster.

Did you do some debugging yourself?
  • when server is started is the database file read correctly
  • when you invoke the getInventory from the client, what is the value of the map at the server? (I would guess it's an empty map too)

  • Oladeji Oluwasayo
    Ranch Hand

    Joined: Sep 10, 2010
    Posts: 101

    Going back to my workstation...
    Oladeji Oluwasayo
    Ranch Hand

    Joined: Sep 10, 2010
    Posts: 101

    After a fine-grained analysis, I was finally able to fix the problem. I will share the cause and the solution later on. Thanks to you all for your suggestion. Off to Pearson VUE site.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Naming.lookUp throws a ClassCastException