0

I have a java application that uses bytedeco/javacv library.

but when I run the application, I am getting the following exception.

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.bytedeco.javacpp.Loader.load(Loader.java:386)
    at org.bytedeco.javacpp.Loader.load(Loader.java:354)
    at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2719)
    at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:391)
    at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:385)
    at com.diyoron.ai.examples.VideoFrameProccessor.main(VideoFrameProccessor.java:38)
Error getting static method ID of org/bytedeco/javacpp/Loader/putMemberOffset

The code is as following,

  String videoPath = video.getAbsolutePath();
  FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(videoPath);
  grabber.start();

According to this following statement in the README.MD

Additionally, we need to either set the javacpp.platform system property (via the -D command line option) to something like android-arm, or set the javacpp.platform.dependencies one to true to get all the binaries for Android, Linux, Mac OS X, and Windows. On build systems where this does not work, we need to add the platform-specific artifacts manually. For examples with Gradle and sbt, please refer to the README.md file of the JavaCPP Presets. Another option available for Scala users is sbt-javacv.

~ Reference GitHub.

I added argument -Djavacpp.platform.dependencies="true", But still I am getting the exception. I am not sure what is causing this issue, I have very less experience in working with c++ wrappers.

PS: I have not installed any c++ dependencies/libraries or open-cv in my machine. And all the solutions are related to Android and I haven't had much luck following those in my java related application.

5
  • How C++ is coming into picture? Commented Jun 8, 2016 at 9:54
  • I am assuming that, javacv is a wrapper for opencv Commented Jun 8, 2016 at 9:55
  • Even then C++ language has no role to play for this question. Commented Jun 8, 2016 at 9:56
  • Do you have any idea on the issue? Commented Jun 8, 2016 at 9:57
  • I am sorry. I am not a Java guy. Note that C++ program gets compiled, and don't need any "C++ virtual machine" kind of thing. Let some Java expert solve your problem! : Commented Jun 8, 2016 at 9:58

1 Answer 1

1

Adding the following dependencies resolved the issue.

        <!-- http://mvnrepository.com/artifact/org.bytedeco/javacv -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- http://mvnrepository.com/artifact/org.bytedeco/javacpp -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
            <version>1.2.1</version>
        </dependency>


        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>opencv</artifactId>
            <version>3.1.0-1.2</version>
        </dependency>

        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>ffmpeg</artifactId>
            <version>3.0.2-1.2</version>
        </dependency>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.