Reputation: 5420
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.
Upvotes: 0
Views: 2826
Reputation: 5420
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>
Upvotes: 1