简体   繁体   中英

java.lang.NoClassDefFoundError

I have no idea of why this is having a runtime error, I have googled the problem and it says that a class that was available during compile time is no longer available at run time.

This is the code:

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
}

I have googled the problem and it says that a class that was available during compile time is no longer available at run time.

That's not correct. That would cause ClassNotFoundException. This one has several causes, but the most common one is that the class in the file isn the class implied by the filename and directory hierarchy.

Basicall java.lang.NoClassDefFoundError thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.

following links will be helpful. This links will guide you slove issue.

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

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

Hope this will be helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM