• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Naming.lookUp throws a ClassCastException

 
Ranch Hand
Posts: 101
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your code has the correct structure (implementing the appropriate interfaces etc.)? Here you can find an example.
 
Oladeji Oluwasayo
Ranch Hand
Posts: 101
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 101
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 101
    Netbeans IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Going back to my workstation...
     
    Oladeji Oluwasayo
    Ranch Hand
    Posts: 101
    Netbeans IDE Oracle Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic