java - java.io.ObjectInputStream 类型无法解析(eclipse)
问题描述
我正在尝试通过 Eclipse(版本 Helios Service Release 1)使用 Java RMI 做一个简单的客户端服务器程序。对于服务器端,我定义了一个接口和一个实现该接口的类。在类中我导入了 java.rmi。, 和 java.rmi.server。API,所以这里是我有错误的地方
java.io.ObjectInputStream 类型无法解析。它是从所需的 .class 文件中间接引用的
我的 JRE 版本是jre1.8.0_221
我尝试通过默认删除和添加 JRE 系统库、清理项目、创建新项目来配置构建路径。基本上,对于此类问题,我已经尝试了 stackOverflow 中提供的大多数选项。
// The Interface
import java.rmi.*;
public interface HelloInterface extends Remote {
public String sayHello(String name) throws RemoteException;
}
// The class where I implement the interface
import java.rmi.*;
import java.rmi.server.*;
public class HelloImpl extends UnicastRemoteObject implements
HelloInterface {
private static final long serialVersionUID = 1L;
public HelloImpl() throws RemoteException {
super( );
}
public String sayHello(String name) throws RemoteException {
return "Hello, World!" + name;
}
}
// The main program
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
public class HelloServer{
public static void main(String args[]){
try {
int port = 16790;
String host = "localhost";
HelloImpl exportedObj = new HelloImpl();
LocateRegistry.createRegistry(port);
String registryURL = "rmi://" + host + ":" + port + "/hello";
Naming.rebind(registryURL, exportedObj);
System.out.println("Hello Server ready.");
}catch (Exception e){
e.printStackTrace();
}
}
}
我期望输出Hello Server Ready
,但程序无法编译显示错误:
java.io.ObjectInputStream 类型无法解析。它是从所需的 .class 文件中间接引用的
解决方案
推荐阅读
- python - read_data_sets 已弃用,将在未来版本中删除。更新说明
- python - 努力用 crontab 运行 python 脚本
- excel - 设置对工作表的引用会产生错误:对象“_Worksheet”的方法“名称”
- powershell - 为什么 Get-CimInstance CIM_LogicalDisk 返回两种类型?
- three.js - Threejs使用mtl在obj文件中导出marchingcubes
- arrays - vba从数组数组中提取数组
- linux-kernel - 有什么方法可以让 uboot 知道内核启动状态
- python - 缺少 1 个必需的位置参数 - Selenium python
- css - 选择没有id的css标签
- javascript - 通过 Ajax 脚本添加多个产品以吸引购物车