0

我不知道为什么会出现运行时错误,我用谷歌搜索了这个问题,它说在编译时可用的类在运行时不再可用。

这是代码:

package examples.RMIShape;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
//import java.rmi.server.UnicastRemoteObject;

public class ShapeListServer {
    public static void main(String args[]){
//      System.setSecurityManager(new RMISecurityManager());
        System.out.println("Main OK");
        try{
            ShapeList aShapelist = new ShapeListServant();
            System.out.println("After create");
            String registryURL = "rmi://localhost:" + "/ShapeList";
            startRegistry();
            Naming.rebind(registryURL, aShapelist);
            System.out.println("ShapeList server ready");
        }catch(Exception e) {
            System.out.println("ShapeList server main " + e.getMessage());
        }
    }

    // This method starts a RMI registry on the local host, if it
    // does not already exists at the specified port number.
    private static void startRegistry()throws RemoteException{
        Registry registry;
        try {
            registry = LocateRegistry.getRegistry();
            registry.list( );  // This call will throw an exception
            // if the registry does not already exist
        }
        catch (RemoteException e) {
            // No valid registry at that port.
            System.out.println ("RMI registry cannot be located at port " + Registry.REGISTRY_PORT );
            registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
            System.out.println("RMI registry created at port " + Registry.REGISTRY_PORT);
        }
    } // end startRegistry
}
4

2 回答 2

1

我用谷歌搜索了这个问题,它说在编译时可用的类在运行时不再可用。

这是不正确的。这将导致 ClassNotFoundException。这有几个原因,但最常见的一个是文件中的类是文件名和目录层次结构所隐含的类。

于 2013-09-29T10:21:22.307 回答
-1

如果 Java 虚拟机或 ClassLoader 实例尝试加载类的定义(作为正常方法调用的一部分或作为使用 new 表达式创建新实例的一部分)并且没有定义可以找到该类。

以下链接会有所帮助。此链接将指导您解决问题。

http://javarevisited.blogspot.in/2011/06/noclassdeffounderror-exception-in.html

http://javaeesupportpatterns.blogspot.in/2012/06/javalangnoclassdeffounderror-how-to.html

希望这会有所帮助

于 2013-09-29T06:51:33.237 回答