ClassNotFoundException

ClassNotFoundException这个错误,比较常见也好理解。

  原因:就是找不到指定的class。

  常见的场景就是:

  1 调用class的forName方法时,找不到指定的类

  2 ClassLoader 中的 findSystemClass() 方法时,找不到指定的类

  3 ClassLoader 中的 loadClass() 方法时,找不到指定的类

java.lang.Class.java:

    /**
* Returns the <code>Class</code> object associated with the class or
* interface with the given string name. Invoking this method is
* equivalent to:
*
* <blockquote><pre>
* Class.forName(className, true, currentLoader)
* </pre></blockquote>
*
* where <code>currentLoader</code> denotes the defining class loader of
* the current class.
*
* <p> For example, the following code fragment returns the
* runtime <code>Class</code> descriptor 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.
*
* @param className the fully qualified name of the desired class.
* @return the <code>Class</code> object for the class with the
* specified name.
* @exception LinkageError if the linkage fails
* @exception ExceptionInInitializerError if the initialization provoked
* by this method fails
* @exception ClassNotFoundException if the class cannot be located
*/
public static Class<?> forName(String className)
throws ClassNotFoundException {
return forName0(className, true, ClassLoader.getCallerClassLoader());
}
    /** Called after security checks have been made. */
private static native Class forName0(String name, boolean initialize,
ClassLoader loader)
throws ClassNotFoundException;

NoClassDefFoundError

这个就比较奇葩了,查找其他的资料是说,通过了编译,但是使用的时候,比如new的时候会出错。

  通过查找资料,搜集到如下的场景:

  1 类依赖的class或者jar不存在

  2 类文件存在,但是存在不同的域中

  3 大小写问题,javac编译的时候是无视大小的,很有可能你编译出来的class文件就与想要的不一样!这个没有做验证。

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

java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别(转)的更多相关文章

  1. java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别

    java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别   以前一直没有注意过这个问题,前两天机缘巧合上网查了一下,然后自 ...

  2. Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.annotation.Around

    1.错误描述 INFO:2015-05-01 11:12:15[localhost-startStop-1] - Root WebApplicationContext: initialization ...

  3. SpringMVC集成AOP错误:java lang classnotfoundexception org aspectj lang joinpoint

    记录自己出现的问题,Spring AOP 使用测试类测试没问题,在SpringMVC启动服务器时出现java lang classnotfoundexception org aspectj lang ...

  4. java.lang.ClassNotFoundException和java.lang.NoClassDefFoundError的区别

    java里生成对象有如下两种方式: 1: Object obj = new ClassName(); 直接new一个对象 2: Class clazz = Class.forName(ClassNam ...

  5. Java基础学习(一)---Java初识

    一.Java介绍 关于Java的诞生和发展网上比较多,在此就不再赘述了,可以参考http://i.cnblogs.com/EditArticles.aspx?postid=4050233. 1.1 J ...

  6. java.lang.ClassNotFoundException: net.sf.json.JSONArray,java.lang.NoClassDefFoundError: net/sf/json/JSONArray jetty跑项目遇到的问题

    2016-05-18 15:44:25 ERROR Dispatcher.error[user:|url:]:L38 - Dispatcher initialization failed Unable ...

  7. Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

    WARNING: Failed to register in JMX: javax.naming.NamingException: Could not load resource factory cl ...

  8. java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.MetadataProvider

    Caused by: java.lang.NoClassDefFoundError: org/hibernate/annotations/common/reflection/MetadataProvi ...

  9. java.lang.ClassNotFoundException: javax.persistence.EntityListeners

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/EntityListene ...

随机推荐

  1. [翻译]Django速查表

    原文在此:https://code.djangoproject.com/wiki/DjangoCheatSheet Django速查表Django教程已经非常好了.这个速查表的作用是创建一个快速开始指 ...

  2. Linux网卡设置

    http://blog.chinaunix.net/uid-20149676-id-1733254.html

  3. 条码知识之十:EAN-128条码(下)

    国际物品编码协会(EAN)和美国统一代码委员会(UCC)将CODE-128码引入EAN/UCC系统,并作如下规定:起始符由一个START A/B/C 加一个辅助字符FNC1构成,以区别普通的CODE- ...

  4. pythonxy 安装

    安装Numpy,发现错误: No module named msvccompiler in numpy.distutils; trying from distutils 目前python除了在 Win ...

  5. Android:源码环境编译自定义的APP到ROM(System Image)中

    有时候我们需要在源码环境中增加自己的应用或模块,随ROM一起发布. 下面讲述相关步骤: 1. 首先可以在SDK环境下进行编码设计(如果你的APP不涉及到emulator无法模拟的硬件的话) 也可以参考 ...

  6. 轻量级数据sqlite的C++调用示例

    原文地址:http://www.cnblogs.com/kfqcome/archive/2011/06/27/2136999.html #include "stdafx.h" #i ...

  7. Centos6.5快速配置可用网卡

    原文链接: Centos6.5快速配置可用网卡 安装完成后,我们启动我们的系统,此时我们的系统,是没有连网的,IP设备,并没有被激活,如果我们使用ifconfig命令查看IP地址,就会发现,此刻的地址 ...

  8. iOS开发UITableViewCell的选中时的颜色设置

    1.系统默认的颜色设置 //无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = ...

  9. DataSource绑定DataTable.Select()显示system.data.DataRow问题解决的方法

    有时候我们须要在控件中绑定DataTable中设定条件过滤后的数据,此时,在winForm环境中,一些控件不能正确绑定并显示数据内容.这是由于DataTable.Select()返回的是DataRow ...

  10. UVA1366-----Martian Mining------DP

    本文出自:http://blog.csdn.net/dr5459 题目地址: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&a ...