File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes ClassCastException returned from PortableRemoteObject.narrow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ClassCastException returned from PortableRemoteObject.narrow" Watch "ClassCastException returned from PortableRemoteObject.narrow" New topic

ClassCastException returned from PortableRemoteObject.narrow

chuck keuper

Joined: Mar 17, 2004
Posts: 22
I have a client

* Created on Oct 12, 2004
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
package com.synesis7.mcsi3.admin.versioncontrol.submitepdr.entity.client;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.synesis7.mcsi3.admin.versioncontrol.submitepdr.entity.interfaces.*;
import java.util.*;

public class EntityClient {

public static void main(String[] args) {
try {
Hashtable env = new Hashtable();

//get naming context
Context context = new InitialContext(env);

//look up jndi name
Object ref = context.lookup(ChangeDocsEntityHome.JNDI_NAME); //JNDI_NAME remote
//Object ref = context.lookup("ejb/ChangeDocsEntityHome"); //JNDI_NAME remote

//look up jndi name and cast to Home interface
ChangeDocsEntityHome home = (ChangeDocsEntityHome)PortableRemoteObject.narrow(ref,ChangeDocsEntityHome.class);
//ChangeDocsEntityLocalHome home = (ChangeDocsEntityLocalHome)PortableRemoteObject.narrow(ref,ChangeDocsEntityLocalHome.class);

Integer value = new Integer("1");
ChangeDocsEntity hl = home.findByPrimaryKey(value);
//ChangeDocsEntityLocal hl = home.findByPrimaryKey(value);
System.out.println("notes = " + hl.getNotes());
System.out.println("reason change = " + hl.getReasonChg());
System.out.println("recommendataion = " + hl.getRecommendation());
} catch (Exception e) {
System.out.println("Exception e = " + e.getMessage());

When I run in debug i get java.lang.ClassCastException at the narrow statement. The Exception e = null. I am running with SunApServ 8 with Eclipse 3.0.1. Any help would greatly be appreciated.
Ali balawala

Joined: Oct 19, 2004
Posts: 4
Why dont you do a System.out.println on "ref" and see if the JNDI lookup is actually returning an object.
If it does retun an object, the output might give you an idea of what it has returned
I agree. Here's the link:
subject: ClassCastException returned from PortableRemoteObject.narrow
It's not a secret anymore!