wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes I'm dying.Please help!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "I Watch "I New topic
Author

I'm dying.Please help!!!

Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
Hi,
I have almost finish my network design and run the server side ok.But when I run the client it
java -Djava.rmi.server.codebase=file:/e:\project/ -cp e:\project suncertify.client.ClientConnection

give an exception:
ClientConnecion:java.lang.ClassCastException: suncertify.server.RemoteAccess_stub

What's wrong?
here's some of my code:

public class ClientConnection{
FactoryInterface factory;
RemoteAccess remote;

...
public void build(String host){
String rmiRegistryHost = host;
try{
factory=(FactoryInterface)Naming.lookup("//"+rmiRegistryHost+"/Factory"); //it's ok
remote= factory.getConnection();//throw exception here

...
}catch(Exception e){
System.out.println("ClientConnection:"+e);
}
}
}
public RemoteAccess getConnection throws RemoteException{
return new RecmoteAccess();
}

RemoteAccess and FactoryConnection are both extends and FactoryConnection will retrun a
unique RemoteAccess
UnicastRemoteObject
Please Help!!!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

You know there are doctors out there that are experts in such cases. They try to treat people so that they don't die.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

First off, you do not need to use codebase.
Codebase is only if you are doing dynamic downloading of Stubs. In order to do this you would have to assume that the assessor has a web server, which they probably do not have. And is also not in the requirements.
So try removing that and run it again and see if you have the same error.
Beside that you path is incorrect because of the slashes.
Also did you run rmic on your two remote classes.
With RMI what is actually returned is the Stub, therefore you need to cast to the DataAccess interface when you get the object in your client.
I'd check those areas too to make sure it is correct.
Mark
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
Hi,

I have try what you told me ,but the exception still exits.
With RMI what is actually returned is the Stub, therefore you need to cast to the DataAccess interface when you get the object in your client.

Maybe the error came from what you said.
I've tried like:
DataInterface remote;
...
remote= (DataInterface)factory.getConnection();
But it still showed that exception.
Why?What's wrong?
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
You are right ,after I change my code to

But it showed another exception:

java.rmi.ServerException:RemoteException occurred in server thread;nested exception is:
java.rmi.UnmarshaException: invalid method hash

What's wrong?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Unmarshalling errors always have to do with RMISecurityManager. If you are using an RMISecurityManager, remove it, you don't really need it for this assignment.
I had had an RMISecurityManager on the client side only, but looking back I would have removed that one too.
Mark
Ray Cheeny
Ranch Hand

Joined: Aug 21, 2002
Posts: 74
Hi Mark,
I haven't used it at all.
But if I do not add codebase in server ,it will
show exception.
And after I add the codebase in server,it works ok.
What's wrong?
George Lawniczak
Greenhorn

Joined: Aug 12, 2002
Posts: 27
Did you create the stubs using RMIC?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

And have a copy of the stubs with the client stuff. You will need to include the stubs in the client's exectuable jar file.
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I'm dying.Please help!!!
 
Similar Threads
Is my design right?
about the stub
factory question
Three questions ablout instructions
confused with singleton