Java에서는 이름 그대로 JVM(Java Virtual Machine)에서 특정 클래스를 로드하려고 할 때 ClassNotFoundException이 발생합니다. 요청한 클래스를 귀하가 지정한 클래스의 경로에서 찾을 수 없습니다. 이는 귀하가 지정한 클래스의 경로가 손상되었음을 의미하며, 이는 Java 세계에서 실제로 흔히 발생하는 문제입니다. 따라서 ClassNotFoundException은 Java에서도 일반적입니다. 이 문제는 Java 초보자에게 매우 혼란스러운 문제이며, ClassNotFoundException을 잡아내거나 호출자에게 던져야 합니다. ClassNotFoundException은 확인된 예외입니다.
광고 이 카테고리에서 인기 있는 강좌 JAVA MASTERY - 전문 분야 | 78 코스 시리즈 | 15가지 모의고사무료 소프트웨어 개발 과정 시작
웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등
Java의 ClassNotFoundException 구문은 다음과 같습니다.
java.lang.ClassNotFoundException:Class_name at location
Java에서 ClassNotFoundException 작업
- 애플리케이션이 클래스를 로드하려고 시도하는 동안 클래스 로더가 지정된 클래스의 경로에서 해당 클래스를 찾을 수 없는 경우, 즉 Java에서 ClassNotFoundException이 발생하는 경우입니다.
- 지정된 클래스의 경로에 없는 매개변수로 클래스의 문자열 이름을 전달하면서 클래스를 로드하기 위해 Class.forName 및 ClassLoader.loadClass를 사용하는 것은 java.lang이 발생하는 일반적인 원인 중 하나입니다. Java의 .ClassNotFoundException.
- Java의 ClassNotFoundException은 확인된 예외이므로 catch하거나 호출자에게 던져야 합니다.
- Classloader를 사용하여 클래스를 간접적으로 로딩하고 있습니다. 결과적으로 Java에서는 런타임 시 ClassNotFoundException이 발생합니다. 지정된 클래스의 경로에 클래스가 있는지 런타임에 Java 컴파일러가 알 수 있는 방법은 없습니다.
- Class.forName을 사용하여 JDBC 드라이버를 로드하려고 시도하고 클래스 경로에 jar 파일을 추가하지 않는 것은 Java에서 ClassNotFoundException이 발생하는 일반적인 예 중 하나입니다.
- Java에서 ClassNotFoundException을 시연하려면 아래 프로그램을 고려하세요.
//a class called program is defined public class Program { //main method is called public static void main(String args[]) { //class not found exception is defined using try and catch block try { // the forname method in class class looks for the mentioned class Class.forName("The Class do not Exist"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
위 프로그램의 출력은 아래 스냅샷과 같습니다.
위 프로그램에는 Program이라는 클래스가 정의되어 있습니다. 그런 다음 기본 메서드가 호출됩니다. 그런 다음 클래스를 찾을 수 없음 예외는 try 및 catch 블록을 사용하여 정의됩니다. 클래스가 존재하지 않습니다. 클래스 로더가 찾으려고 하는 java 클래스와 클래스의 forname 메소드가 언급된 클래스를 찾지만 찾지 못합니다. 따라서 ClassNotFoundException이 발생합니다. 프로그램의 출력은 위의 스냅샷과 같습니다.
건축자
Java에는 ClassNotFoundException에 대한 여러 생성자가 있습니다. 그들은:
- ClassNotFoundException(): 스택의 현재 추적을 포함하는 새로운 ClassNotFoundException이 생성됩니다.
- ClassNotFoundException(String): 스택의 현재 추적과 지정된 메시지를 포함하는 새로운 ClassNotFoundException이 생성됩니다.
- ClassNotFoundException(IntPtr, JniHandleOwnership): JNI 객체를 생성하는 동안 표현을 관리하는 동안 이 생성자가 사용되며 런타임에서 이를 호출합니다.
- ClassNotFoundException(String, Throwable): 스택의 현재 추적과 지정된 메시지의 세부정보 및 클래스를 로드하려고 할 때 발생하는 예외를 포함하는 새로운 ClassNotFoundException이 생성됩니다. .
Java ClassNotFoundException의 예
아래에 언급된 예는 다음과 같습니다.
예시 #1
ClassNotFoundException을 시연하는 Java 프로그램:
코드:
//a class called exceptiondemo is defined public class Exceptiondemo { //a string variable is defined private static final String DRIVE_CLASS = "com.mysql.jdbc.Driver"; //main method is called including the exception public static void main(String[] args) throws Exception { System.out.println("MySQL JDBC driver loading attempt"); //the forname method in class class looks for the mentioned class Class.forName(DRIVE_CLASS); } }
위 프로그램의 출력은 아래 스냅샷과 같습니다.
위 프로그램에는 Exception 데모라는 클래스가 정의되어 있습니다. 그런 다음 기본 메서드가 호출됩니다. 그런 다음 JDBC 드라이버 경로가 할당되는 문자열 변수가 정의됩니다. 그런 다음 예외를 발생시키는 기본 메서드가 호출됩니다. 클래스 로더는 지정된 클래스의 JDBC 드라이버 경로를 찾으려고 시도하고 클래스의 forname 메소드는 언급된 클래스를 찾지만 실패합니다. 따라서 ClassNotFoundException이 발생합니다. 프로그램의 출력은 위의 스냅샷과 같습니다.
예시 #2
ClassNotFoundException(String)을 시연하는 Java 프로그램
코드:
//a class called check is defined public class Check { //main method is called public static void main(String args[]) { //class not found exception is defined using try catch block try { //the forname method in class class looks for the mentioned class Class.forName("Demonstrating class not found exception"); } catch(ClassNotFoundException e) { //the string specified along with the class not found exception is displayed. System.out.println("There is no class as specified in the path " + e); } } }
위 프로그램의 출력은 아래 스냅샷과 같습니다.
In the above program, a class called check is defined. Then the main method is called. Then the main method is called. Then class not found exception is defined by using try and catch block. Then the forename method in class looks for the mentioned class, which it fails to find; hence the ClassNotFoundException is thrown and the string specified as a detailed message along with the class not found exception is displayed. The output of the program is as shown in the snapshot above.
How to Avoid ClassNotFoundException?
Steps to avoid ClassNotFoundException:
- The file of the class causing the problem on which the jar file is present must be found out.
- We should check if the path of the class or classpath consists of that jar. If the jar is not present in the classpath or path of the class, the class must be added in the class or classpath path.
- If the class is present in the class or classpath path, then the chances are that there is an overriding of classpath or path of the class or the path specified in the jar file or the script used for starting up is being used by the application. To solve this problem, we need to find the exact path of the class that is being used by the application.
Conclusion
In this tutorial, we understand the concept of Class Not Found Exception in Java through definition, the syntax of Class Not Found Exception in Java, working of Class Not Found Exception in Java, and their constructors through examples and their outputs.
위 내용은 자바 클래스NotFoundException의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

이 기사에서는 Java 프로젝트 관리, 구축 자동화 및 종속성 해상도에 Maven 및 Gradle을 사용하여 접근 방식과 최적화 전략을 비교합니다.

이 기사에서는 Maven 및 Gradle과 같은 도구를 사용하여 적절한 버전 및 종속성 관리로 사용자 정의 Java 라이브러리 (JAR Files)를 작성하고 사용하는 것에 대해 설명합니다.

이 기사는 카페인 및 구아바 캐시를 사용하여 자바에서 다단계 캐싱을 구현하여 응용 프로그램 성능을 향상시키는 것에 대해 설명합니다. 구성 및 퇴거 정책 관리 Best Pra와 함께 설정, 통합 및 성능 이점을 다룹니다.

이 기사는 캐싱 및 게으른 하중과 같은 고급 기능을 사용하여 객체 관계 매핑에 JPA를 사용하는 것에 대해 설명합니다. 잠재적 인 함정을 강조하면서 성능을 최적화하기위한 설정, 엔티티 매핑 및 모범 사례를 다룹니다. [159 문자]

Java의 클래스 로딩에는 부트 스트랩, 확장 및 응용 프로그램 클래스 로더가있는 계층 적 시스템을 사용하여 클래스로드, 링크 및 초기화 클래스가 포함됩니다. 학부모 위임 모델은 핵심 클래스가 먼저로드되어 사용자 정의 클래스 LOA에 영향을 미치도록합니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

WebStorm Mac 버전
유용한 JavaScript 개발 도구

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
