Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ClassCastException in RMI application

Reply
Thread Tools

ClassCastException in RMI application

 
 
atilagunes@gmail.com
Guest
Posts: n/a
 
      05-02-2007
Hello,

i found some mails complaining about ClassCast Exception but mine is a
bit different and i coulnt find any explanation.. Please help me..


********** CList Interface *************
import java.rmi.*;
import java.util.Properties;

public interface CList extends Remote{
public Properties getClients() throws RemoteException;
}



********** CListImpl ******************
import java.rmi.*;
import java.rmi.server.*;
import java.util.Properties;

public class CListImpl extends UnicastRemoteObject
implements CList {
public CListImpl () throws RemoteException {
}

public Properties getClients() throws RemoteException{
return clients;
}
public Properties clients=new Properties(); // I'm trying to return
back a Properties file..
}


*********** CListClient ****************
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;
import java.util.Properties;

public class CListClient {
public static void main(String[] args)
{
System.setProperty("java.security.policy", "client.policy");
System.setSecurityManager(new RMISecurityManager());
String url = "rmi://localhost/";

try
{

Context namingContext = new InitialContext();
CList c1 = (CList) namingContext.lookup(url +
"akclients"); // Register name
Properties clients=new Properties();
clients=(Properties)c1.getClients();
System.out.println(clients);

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


************** In the Server side *******************
import java.util.Properties;
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;

public class Server {
public CListImpl c1;
public Server(){

}


}

 
Reply With Quote
 
 
 
 
atilagunes@gmail.com
Guest
Posts: n/a
 
      05-02-2007
sorry , i send wrongly before complate the mail..
i'm going on..

************** In the Server side *******************
import java.util.Properties;
import java.rmi.*;
import java.rmi.server.*;
import javax.naming.*;

public class Server {

public CListImpl c1;

public Server(){

try{
c1 = new CListImpl ();
Context namingContext = new InitialContext ();
namingContext.rebind ("rmi:akclients", c1);
}
catch(Exception e){
e.printStackTrace();
}

}
}


server sides works fine.. but client side gives an error at
CListClient.java when it executes "" CList c1 = (CList)
namingContext.lookup(url + "akclients"); "" line..
it gives java.lang.ClassCastException: CListImpStub cannot be cast to
CList at CListClient.main<CListClient.java:17> that i wrote above what
the line is.

CListImpl uses Properties but CList interface cant cast it.. How can i
send an object ? Please help mee, i need to use this in my project and
i'm not familiar with RMI actually..

 
Reply With Quote
 
 
 
 
Esmond Pitt
Guest
Posts: n/a
 
      05-03-2007
I suspect you have the CList interface in two packages, so the CList
that is implemented by CListImplStub is different from the CList the
client is using. You can't do that. You have to use the *same* remote
interface class, not a similar one with the same name in a different
package.
 
Reply With Quote
 
atilagunes@gmail.com
Guest
Posts: n/a
 
      05-03-2007
Yes, they are in different package.. Coz server side project and
client side projects are in different project, thats why they are in
different package.. but the code which are implemented in CList
interface and CListImpl are same as codes... According to your mail,
i should use same package name for both sides, hmmm, or can i copy
the stub to another project as compiled as class file ?

On 3 Mayıs, 09:44, Esmond Pitt <(E-Mail Removed)> wrote:
> I suspect you have the CList interface in two packages, so the CList
> that is implemented by CListImplStub is different from the CList the
> client is using. You can't do that. You have to use the *same* remote
> interface class, not a similar one with the same name in a different
> package.



 
Reply With Quote
 
Esmond Pitt
Guest
Posts: n/a
 
      05-04-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Yes, they are in different package.. Coz server side project and
> client side projects are in different project, thats why they are in
> different package.. but the code which are implemented in CList
> interface and CListImpl are same as codes... According to your mail,
> i should use same package name for both sides, hmmm,


I didn't say that at all. I said you had to use the same remote
interface class at both sides and that includes not changing its package
name. How you achieve sharing of that single class between multiple
projects is up to you. That doesn't imply that both entire projects
should be in the same package.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does java.rmi.Naming not implement interface java.rmi.Registry? Jan Schulze Java 1 03-26-2005 07:45 AM
RMI Vs RMI over IIOP JScoobyCed Java 1 01-28-2005 09:54 AM
RMI, JINI or RMI/IIOP Buu Nguyen Java 1 08-25-2004 11:28 AM
Runtime ClassCastException when assigning clone of Area subclass Richard A. DeVenezia Java 2 01-08-2004 01:06 PM
ClassCastException and ClassLoaders Luther Baker Java 3 09-10-2003 02:56 AM



Advertisments