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:
java.sun.com/j2se/1.4.2/docs/guide/idl/jidlNaming.html#example3

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