2014-02-27 2 views
1

"우분투 셸에서"javac cancelladir.java "라고 쓸 때 디렉토리 이름"cancelladir "에있는"cancelladir "이라는 파일 java를 만들었습니다. cancelladir.class하지만 명령 "자바 cancelladir"로 파일 자바를 실행하려고 할 때이 같은 일부 오류가 있습니다java.lang.NoClassDefFoundError : and other error

Exception in thread "main" java.lang.NoClassDefFoundError: cancelladir (wrong name: cancelladir/cancelladir) 
    at java.lang.ClassLoader.defineClass1(Native Method) 
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800) 
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) 
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361) 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358) 
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482) 

가 이미 export CLASSPATH=.:/home/lisa/graphhopper/graphhopperAndrea/web/src/main/webapp/cancelladir에서 클래스 경로를 설정하고 다시 컴파일하지만, 아무것도 변화를 시도했다. 무엇이 문제입니까 ?? 내가 뭘해야 해?

+0

당신은 코드의 어떤 라인이 오류가 발생 찾을 수있는 코드를 디버깅 했습니까? – lakshman

+0

클래스 패스에서 클래스를 찾을 수 없습니다. 새 명령 창을 열고 classpath를 export CLASSPATH = $ {CLASSPATH} :와 같이 설정하십시오. – Jay

+0

작성한 코드와 절차는 무엇입니까? 미안하지만 나는 자바에서 초심자이다. – Zoifil

답변

1

코드를 컴파일하고 나면 프로그램의 각 클래스에 .class 파일이 생깁니다. 이 2 진 파일은 Java가 프로그램을 실행하기 위해 해석하는 바이트 코드입니다. NoClassDefFoundError는 클래스를 동적으로로드하는 클래스 로더가 사용하려고하는 클래스의 .class 파일을 찾을 수 없음을 나타냅니다. 코드를 실행할 때 classpath 옵션을 설정하지 않았 음을 나타냅니다. 이 링크는 실행할 때 클래스 패스를 설정하는 방법을 설명합니다

1

1) 새 쉘을 열고 이와 같은 간단한 프로그램을 추가하십시오.
) javac Hello.java를 사용하여 Java 코드 컴파일
3) java Hello를 사용하여 코드 실행
문제가 계속 발생하면 제대로 작동합니다.

enter image description here

+0

동일한 문제가 있습니다. = ( – Zoifil

+0

이 간단한 Hello.java를 시도 했습니까? 프로그램을? 스택 추적을 붙여 넣을 수 있습니까? – Jay

+0

죄송합니다 지금 작동합니다 (Hello.java의 간단한 코드 만) – Zoifil