2016-06-13 2 views
0

내 코드는 성공적으로 컴파일되지만 실행되지 않습니다. 다음은 관련 코드입니다. "javac -cp :/Users/DavidOwens/javacv-bin/* ICGPixelGetter.java"로 컴파일하고 javacv-bin은 내 사용자 폴더에 있습니다.패키지와 일치하지 않는 .NoClassDefFoundError

//Takes a video file and gets frame grabs of it 
    private ArrayList<ImageView> getFrameGrabs() { 
     try{ 
      //get video frames 
      FFmpegFrameGrabber g = new FFmpegFrameGrabber("for david.mpeg"); 

      g.start(); 

      for (int i = 1 ; i < 10 ; i++) { 
       ImageIO.write(g.grab().getBufferedImage(), "jpg", 
        new File("frame-dump/video-frame-" 
         + System.currentTimeMillis() + ".png")); 
       } 

      g.stop(); 
      } 

      catch(Exception ex){ 
       System.out.println("Frame Grab IOException"); 
      } 
     return frameGrabs; 
    }//END METHOD 

및 주요 응용 프로그램의 시작은

import java.util.*; 
import java.io.*; 
import javax.imageio.*; 
import java.awt.*; 
import java.awt.image.BufferedImage; 
import javafx.application.Application; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.event.EventType; 
import javafx.stage.Stage; 
import javafx.scene.Scene; 
import javafx.scene.input.*; 
import javafx.scene.control.ContentDisplay; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.scene.layout.Pane; 
import javafx.scene.layout.BorderPane; 
import javafx.scene.control.Button; 
import javafx.scene.paint.Color; 
import javafx.scene.text.*; 
import javafx.scene.image.*; 
import javafx.geometry.Insets; 
import javafx.geometry.Pos; 
import org.bytedeco.javacv.*; 
import org.bytedeco.javacpp.*; 

@Override //Override start method in Application class 
public void start(Stage primaryStage) { 

    getFrameGrabs(); 

    //bunch of code that works fine 
} 

나는이 스택 트레이스

Exception in Application start method 
    Exception in thread "main" java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) 
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.NoClassDefFoundError: org/bytedeco/javacv/FFmpegFrameGrabber 
    at ICGPixelGetter.getFrameGrabs(ICGPixelGetter.java:112) 
    at ICGPixelGetter.start(ICGPixelGetter.java:57) 
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) 
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) 
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) 
Caused by: java.lang.ClassNotFoundException: org.bytedeco.javacv.FFmpegFrameGrabber 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
    ... 8 more 
+0

컴파일하는 방법과 관련이 없습니다. 그것은 당신이 ** 실행하는 ** ** 문제입니다. –

+0

@JBNizet "java filename"과 함께 터미널을 통해 프로그램을 실행할 때이 오류가 발생합니다. 어떻게 다르게 실행할 것을 권장합니까? –

+0

글쎄, 당신의 클래스는'.'에있는 클래스들과'. :/Users/DavidOwens/javacv-bin /'에있는 모든 jar에 의존합니다. 따라서, 컴파일 할 때와 마찬가지로, 현재 디렉토리와 jar는 classpath에 있어야한다 : java -cp : :/Users/DavidOwens/javacv-bin/* ICGPixelGetter'. 클래스를 기본 패키지 BTW에 넣는 것은 끔찍한 습관입니다. –

답변

0

이유 등을 컴파일하는 IDE를 사용하지를 얻을 방법은? 당신은 당신의 프로젝트에 도서관을 포함시켜야합니다.

0

javacv-bin/에 클래스 패스에 포함시키려는 JAR 파일이 포함되어 있습니까? 그렇지 않으면 클래스 경로에 대한 구문이 잘못되었습니다. 표시되는 구문은 ./을 루트로하는 모든 클래스 트리와 javacv-bin/에 포함 된 모든 JAR 파일을 포함합니다. .classjavacv-bin/ 내에있는 파일을 찾을 수 없습니다.

http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html이 유용 할 것입니다. 항상 RTM.

또한 자바 코드는 컴파일되지 않습니다. http://sscce.org/에 명시된대로 사례를 떼어 낸 경우 전체를 제공해주십시오.

+0

또한 수업을 패키지로 만들어야합니다. –

+0

예 javacv-bin에는 FFmpegFrameGrabber를 처리 할 jar 파일이 들어 있습니다. –

관련 문제