Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB and other Java EE Technologies and the fly likes why did't cast the object to TestHome type? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "why did Watch "why did New topic
Author

why did't cast the object to TestHome type?

gagaghost
Greenhorn

Joined: Apr 23, 2002
Posts: 10
hi.
I have written a Session EJB by jbuilder7.0 and deloyed it into the weblogic6.1.but when I test the EJB at client,the test program throwed a error,how can I do it?
the source:
import java.util.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;

public class testejb
{
public static void main(String args[])
{
try
{
Properties p=System.getProperties();

p.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.setProperty(Context.PROVIDER_URL,"t3://127.0.0.1:7001");

Context ctx=new InitialContext(p);
Object ref=ctx.lookup("TestBean");
TestHome data=(TestHome) PortableRemoteObject.narrow(ref, TestHome.class);

if(data instanceof TestHome)
{
System.out.println("yes.");
}else{
System.out.println("no.");
}


}catch(Exception ex){
ex.printStackTrace();
}

}
}
error:
E:\java>java testejb
java.lang.ClassCastException
at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(Unkno
wn Source)
at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
at testejb.main(testejb.java:20)
M.C. Horn
Greenhorn

Joined: Sep 18, 2002
Posts: 28
What Interface does TestHome implement ?
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
"gagagohst",
Welcome to JavaRanch and thanks for joining us, but your publically displayed name must meet the JavaRanch naming policy.
You can edit your profile here.
Thanks in advance,
Simon, Bartender "J2EE and EJB" forum
Andras Nemeth
Ranch Hand

Joined: Jul 31, 2001
Posts: 80
Did you try to write out the result of the lookup? (ref) Isn't it null?
What is the JNDI name of the bean (TestHome)?
Ban
Andras Nemeth
Ranch Hand

Joined: Jul 31, 2001
Posts: 80
I meant of course TestBean instead of TestHome!
Cheers,
Ban
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why did't cast the object to TestHome type?