0
回答
RMI编译异常,无法通过变异,提示缺少字符
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

@红薯 你好,想跟你请教个问题:为什么我在DOS窗口编译RMI服务端文件的实现类的时候总是到了实现接口的时候提示找不到字符呢?能帮我解决一下这问题吗?麻烦了。

package rmi.server;
//Calculator.java 
//define the interface 
import java.rmi.Remote; 

public interface Calculator extends Remote 
{ 
 public long add(long a, long b) 
 throws java.rmi.RemoteException; 

 public long sub(long a, long b) 
 throws java.rmi.RemoteException; 

 public long mul(long a, long b) 
 throws java.rmi.RemoteException; 

 public long div(long a, long b) 
 throws java.rmi.RemoteException; 
} 

package rmi.server;

import java.rmi.server.UnicastRemoteObject;

public class CalculatorImpl extends UnicastRemoteObject implements Calculator {

	// 这个实现必须有一个显式的构造函数,并且要抛出一个RemoteException异常
	public CalculatorImpl() throws java.rmi.RemoteException {
		super();
	}

	public long add(long a, long b) throws java.rmi.RemoteException {
		return a + b;
	}

	public long sub(long a, long b) throws java.rmi.RemoteException {
		return a - b;
	}

	public long mul(long a, long b) throws java.rmi.RemoteException {
		return a * b;
	}

	public long div(long a, long b) throws java.rmi.RemoteException {
		return a / b;
	}
}

package rmi.server;

import java.rmi.Naming;

public class CalculatorServer {

	public CalculatorServer() {
		try {
			Calculator c = new CalculatorImpl();
			Naming.rebind("rmi://localhost:1099/CalculatorService", c);
		} catch (Exception e) {
			System.out.println("Trouble: " + e);
		}
	}

	public static void main(String args[]) {
		new CalculatorServer();
	}
}


package rmi.client;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;

import rmi.server.Calculator;

public class CalculatorClient {

	public static void main(String[] args) {
		try {
			Calculator c = (Calculator) Naming.lookup("rmi://localhost/CalculatorService");
			System.out.println(c.sub(4, 3));
			System.out.println(c.add(4, 5));
			System.out.println(c.mul(3, 6));
			System.out.println(c.div(9, 3));
		} catch (MalformedURLException murle) {
			System.out.println();
			System.out.println("MalformedURLException");
			System.out.println(murle);
		} catch (RemoteException re) {
			System.out.println();
			System.out.println("RemoteException");
			System.out.println(re);
		} catch (NotBoundException nbe) {
			System.out.println();
			System.out.println("NotBoundException");
			System.out.println(nbe);
		} catch (java.lang.ArithmeticException ae) {
			System.out.println();
			System.out.println("java.lang.ArithmeticException");
			System.out.println(ae);
		}
	}
}

举报
jiahuawalden
发帖于4年前 0回/96阅
顶部