}
int port =new Integer(args[1]).intValue();
Registry reg=null;
if(args[0].equals("true")) {
reg=LocateRegistry.createRegistry(port);
System.out.println("Successfully created registry");
}
else {
reg=LocateRegistry.getRegistry(port);
System.out.println("Connected to existing registry.");
}
Flip flip=new Flip(reg);
}
public Flip(Registry reg) throws Exception,RemoteException {
super();
reg.rebind("Flip",this);
System.out.println("Flip object bound");
}
public int flip(int i) throws RemoteException {
return i*-1;
}
}报错:
symbol : class IFlip
location: class com.wiley.compBooks.roman.rmi.flip.Flip
public class Flip extends UnicastRemoteObject implements IFlip {
^
1 error
救命!
int port =new Integer(args[1]).intValue();
Registry reg=null;
if(args[0].equals("true")) {
reg=LocateRegistry.createRegistry(port);
System.out.println("Successfully created registry");
}
else {
reg=LocateRegistry.getRegistry(port);
System.out.println("Connected to existing registry.");
}
Flip flip=new Flip(reg);
}
public Flip(Registry reg) throws Exception,RemoteException {
super();
reg.rebind("Flip",this);
System.out.println("Flip object bound");
}
public int flip(int i) throws RemoteException {
return i*-1;
}
}报错:
symbol : class IFlip
location: class com.wiley.compBooks.roman.rmi.flip.Flip
public class Flip extends UnicastRemoteObject implements IFlip {
^
1 error
救命!
???
import java.rmi.server.*;
import java.rmi.registry.*;interface IFlip extends Remote
{
public int flip(int i) throws RemoteException;
}public class Flip extends UnicastRemoteObject implements IFlip
{ public static void main(String[] args)
{
if(args.length!=2)
{
System.err.println("Syntax: Flip<true|false><port>");
System.err.println();
System.err.println("true demarcates to start RMI Registry, "+
"false demarcates to bind to existing one.");
System.err.println("port is the port # for RMI Registry.");
System.exit(-1);
}
int port =new Integer(args[1]).intValue();
Registry reg=null;
if(args[0].equals("true"))
{
try
{
reg = LocateRegistry.createRegistry(port);
}
catch(Exception e)
{
}
System.out.println("Successfully created registry");
}
else
{
try
{
reg = LocateRegistry.getRegistry(port);
}
catch(Exception e)
{
System.out.println("Connected to existing registry.");
}
}
try
{
Flip flip=new Flip(reg);
}
catch(Exception e)
{
}
}
public Flip(Registry reg) throws Exception,RemoteException
{
super();
reg.rebind("Flip",this);
System.out.println("Flip object bound");
}
public int flip(int i) throws RemoteException {
return i*-1;
}
}你把这个试一下其实你刚才也可以编译的,不过你的classpath中要包含这个文件的路径外还有你需要catch一些一定需要捕捉的exception