I get the following error while casting NamingContext type to NamingContextExt type.

java.lang.ClassCastException: org.omg.CosNaming._NamingContextStub

Statement causing the error is:
Java Code:
NamingContextExt ctx2 = (NamingContextExt)ctx.bind_new_context(name2);
I am using jre 1.6.
This example is from Corba tutorial of SUN:

For me it looks like a valid casting, what might be the reason?
How can the problem be solved?