首页 > 解决方案 > 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 文件中间接引用的

项目要素

标签: java

解决方案


推荐阅读