Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassCastException: Cannot narrow...

 
Ben Roy
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting this error when I attempt to get a handle for an entity bean:
java.lang.ClassCastException: Cannot narrow without a stub class: hvr._TblsubscribersHome_Stub
The code that is leading up to this exception is:
public class TblsubscribersTestClient1
{
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 50;
private boolean logging = true;
private TblsubscribersHome tblsubscribersHome = null;
private Tblsubscribers tblsubscribers = null;
/**Construct the EJB test client*/
public TblsubscribersTestClient1()
{
long startTime = 0;
if (logging)
{
log("Initializing bean access.");
startTime = System.currentTimeMillis();
}
try
{
//get naming context
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("Tblsubscribers");
//cast to Home interface
tblsubscribersHome = (TblsubscribersHome) PortableRemoteObject.narrow(ref, TblsubscribersHome.class);

The last line is where the exception is thrown. Almost the entire bean was auto generated by JBuilder4, as was this test client application. I am too new to this environment to be able to determine what is causing this problem, and haven't managed to find anything in any help files which explains it. Thanks for your help!
 
Preethi Chaloori
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!Ben,
I think the problem is more related to the Casting in general than specifically to the bean that you have written. There are certain rules you need to follow when casting.
The ClassCastException is generally thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
I am new to EJB too and there could be something that I do not know.

Good luck,
Preethi
 
Thillai Sakthi
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Actually I am also using JBuilder4 for developing EJB applications. I also encountered this problem once. The IDE generates somewhere around 10-15 files for which you don't have any control. Try shutting down JBuilder and restart it once again. If still problem persists, check visibroker option in Tools menu.
MK
 
Venkat Ammisetty
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
What ever Preeti and MK said is right.
I too got this problem in two cases
(1) Exchanging datatypes from database to Java.
ex: if you pass String variable in database to int in Java.
(2) When ever you create JAR file some of the previous version of your file resides in temp directory,you remove those file and create jar file again.
One solution is "you place this in you client program instead of simply hvr hvr._TblsubscribersHome_Stub".
If this don't solve your problem i am very SORRY.
Bye
Venkat
 
Nauman Rafique
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was also having this problem. I was accessing ejb from a jsp. The solution i found is this :
Remove the class files, which my jsp( client of ejb) was using, like the class files of the ejb, from the class path of weblogic
e.g., my class files are in ../WEB-INF/classes w.r.t. to my application root. Remove them before starting weblogic ( or remove them and restart).
If you still have the problem, find any class files related to your application in weblogic folder and remove them( you might have put them there by mistake).
Regards
Nauman

Originally posted by Ben Roy:
I'm getting this error when I attempt to get a handle for an entity bean:
java.lang.ClassCastException: Cannot narrow without a stub class: hvr._TblsubscribersHome_Stub
The code that is leading up to this exception is:
public class TblsubscribersTestClient1
{
private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first.";
private static final int MAX_OUTPUT_LINE_LENGTH = 50;
private boolean logging = true;
private TblsubscribersHome tblsubscribersHome = null;
private Tblsubscribers tblsubscribers = null;
/**Construct the EJB test client*/
public TblsubscribersTestClient1()
{
long startTime = 0;
if (logging)
{
log("Initializing bean access.");
startTime = System.currentTimeMillis();
}
try
{
//get naming context
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("Tblsubscribers");
//cast to Home interface
tblsubscribersHome = (TblsubscribersHome) PortableRemoteObject.narrow(ref, TblsubscribersHome.class);

The last line is where the exception is thrown. Almost the entire bean was auto generated by JBuilder4, as was this test client application. I am too new to this environment to be able to determine what is causing this problem, and haven't managed to find anything in any help files which explains it. Thanks for your help!

 
Ilya Dorfman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying JBuilder4 in combination with Inprise server and I never got passed this error.
 
glenn
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same problem can anyone help?
 
Gustavo Arellano
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using jBuilder, you can solve this problem by setting up the values of VisiBroker on the CORBA secction from the "Enterprise Setup" to the values:
Path to ORB tools: <path to the bin directory of your AppServer>
Libary for proyects: Borland Enterprise Server 5.2.1 Cliente

Hope this help!!!
Gustavo Arellano
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!