This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes P.R.O.narrow throws ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "P.R.O.narrow throws ClassCastException" Watch "P.R.O.narrow throws ClassCastException" New topic

P.R.O.narrow throws ClassCastException

Toby Eggitt
Ranch Hand

Joined: Dec 08, 2004
Posts: 44
I'm trying to work the example in HeadFirst EJB, the Advisor one... I'm
using the Referece Implementation (1.4). I compile, package, and deploy
happily enough (after a couple of hours searching these archives to
discover the need for "Context.INITIAL_CONTEXT_FACTORY" and stuff), but
when I try to run the client, I get a class cast exception. This
exception is being created by the narrow method itself. I separated out
the narrow from the Java-level cast so I could distinguish. The error
looks like this:

looking for a Advisor
got something back, it's a
...snip snip, lots of boring numbers
at javax.rmi.PortableRemoteObject.narrow(
at AdviceClient.go(
at AdviceClient.main(

The stuff about "Looking for an Advisor" and "got something back, it's a
blah blah" are debug messages I added so I could see confidently what the
lookup was looking for, and what was returned. I just do a S.o.p on the
returned object from the lookup.

As you see, the narrow then explodes, apparently claiming that what the
lookup returned can't be turned into an AdviceHome.

Any suggestions? I have undeployed and redeployed till I'm blue in the
face, and I'm currently reinstalling the RI from scrach in case there was
anything stupid left behind (I tried to use JBoss earlier, but that was awful! [or maybe I just don't understand it])

I see from the archives that this has been asked several times in the past,
but there don't seem to be any definitive statements on what fixed it. I've
tried the ideas that were hinted at in those discussions, but to no avail.
Did those folks just give up, run away, and join the circus instead?

Thanks for any help you can offer,
I agree. Here's the link:
subject: P.R.O.narrow throws ClassCastException