Classnotfoundexception and NoClassDefFoundError occur when the JVM cannot find the class requested by the classpath.
Classnotfoundexception is a checked exception that occurs when an application attempts to load a class with its fully qualified name and cannot find it on the classpath.
Mainly occurs when trying to use class forName()、ClassLoader. loadClass()、ClassLoader. Findsystemclass() failed to load class.
For example: load a class that does not exist
In case of NoClassDefFoundError (Java project fhadmin. CN), the system cannot operate normally and cannot be recovered. When the JVM tries the following:
Instantiate a class with new
Loading classes using method calls
When the compiler can successfully compile the class, but the Java runtime cannot find the class file, a modification error will occur. It usually occurs when an exception occurs when executing a static block or initializing a static field of a class, so the class initialization fails
The main reason is that the runtime class file (in the classpath) is not available. resolvent:
Ensure that the class or jar containing the class can be used in the classpath. If not, you need to add it manually.
If it is available on the classpath, it is possible that the path is overwritten. At this time, you need to find the exact path of the class.
Classnotfoundexception and NoClassDefFoundError are both because the Java runtime cannot find the relevant class.
Classnotfoundexception is an exception thrown when the Java runtime loads a class, and the name is provided at runtime.
NoClassDefFoundError means that this class exists at compile time, but cannot be found on the path by Java runtime.
This work adoptsCC agreement, reprint must indicate the author and the link to this article