Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
exception
class
error

How to resolve the "java.lang.ClassNotFoundException" in Java

Educative Answers Team

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 can​not 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);
    }
}
svg viewer

Solution

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.

RELATED TAGS

java
exception
class
error
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring