The ClassNotFoundException is thrown to indicate that the specified class cannot be found in the classpath. The following piece of code tries to load the class using forName()
, but the class name cannot be found. Thus, the exception is thrown.
package main.java;class MAIN {private String TEMP = "Educative";public static void main(String[] args) {Class loadClass = Class.forName(TEMP);}}
Verify the specified class name and check whether or not the .jar
file exists in the classpath. If it already exists, then make sure that it is not overridden in our program. If the file does not exist, then simply add the .jar
file in the classpath.
Free Resources