The difference between java.lang.ClassNotFoundException and Java.lang.NoClassDefFoundError (turn)

Source: Internet
Author: User

ClassNotFoundException

ClassNotFoundException This error, more common or understanding.

Reason: The specified class could not be found.

A common scenario is:

1 The specified class was not found when calling the Forname method of class

2 ClassLoader in the Findsystemclass () method, the specified class was not found

3 ClassLoader in the LoadClass () method, the specified class was not found

Java.lang.Class.java:

    /** * Returns the <code>Class</code> object associated with the Class or *  interface with the given string name. Invoking this method was * equivalent to: * * <blockquote><pre> * class.forname (ClassName, Tru E, currentloader) * </pre></blockquote> * * where <code>currentLoader</code> denotes t     He defining class loader of * the current class. * * <p> For example, the following code fragment returns the * runtime <code>Class</code> DESCRI   Ptor for the class named * <CODE>JAVA.LANG.THREAD</CODE>: * * <blockquote><pre> *     class&nbsp;t&nbsp;= class.forname ("Java.lang.Thread") * </pre></blockquote> * <p>     * A call to <tt>forname ("X") </tt> causes the class named * <tt>X</tt> to be initialized. *     * @paramClassName The fully qualified name of the desired class. * @returnThe <code>Class</code> object for the Class with the * specified name. * @exceptionLinkageerror If the linkage fails *@exceptionExceptionininitializererror If the initialization provoked * by this method fails *@exceptionClassNotFoundException If the class cannot be located*/     Public StaticClass<?>forname (String className)throwsClassNotFoundException {returnFORNAME0 (ClassName,true, Classloader.getcallerclassloader ()); }

    /***/    privatestaticnativeboolean  Initialize,                        ClassLoader loader)     throws ClassNotFoundException;

Noclassdeffounderror

This is more wonderful, looking for other information is that through the compilation, but when used, such as new when the error.

By finding the data, the following scenarios are collected:

Class 1-dependent classes or jars do not exist

Class 2 file exists, but exists in a different domain

3 case, Javac compile time is ignored size, it is likely that you compiled the class file is not the same as you want! This does not do validation.

Http://www.cnblogs.com/xing901022/p/4185514.html

The difference between java.lang.ClassNotFoundException and Java.lang.NoClassDefFoundError (turn)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.