ClassNotFoundException vs NoClassDefFoundError

前端 未结 9 1902
半阙折子戏
半阙折子戏 2020-12-23 11:59

I have gone through this thread What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException? This is what one of the ans,which has max u

9条回答
  •  醉话见心
    2020-12-23 12:38

    The difference depends on who asked the class to be loaded:

    • ClassNotFoundException is thrown when the code is directly trying to load a class, passing the String argument representing a Fully Qualified Name of the class.
      • e.g. Class.forName(String), or ClassLoader.loadClass(String).
    • NoClassDefFoundError is thrown when the JVM is asked to load a class indirectly.
      • e.g. when class A is using class B and class B is not on classpath, NoClassDefFoundError will be thrown.

提交回复
热议问题