Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why did't cast the object to TestHome type?

 
gagaghost
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Interface does TestHome implement ?
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant of course TestBean instead of TestHome!
Cheers,
Ban
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic