Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting "java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil" although platform dependencies are included #109

Closed
yngvesl opened this issue Mar 29, 2015 · 14 comments

Comments

@yngvesl
Copy link

yngvesl commented Mar 29, 2015

I've tried to run a simple application with an FFMmpegFrameGrabber.
I've included javacv 0.10 in my pom and ran the
$ mvn package exec:java -Dplatform.dependencies -Dexec.mainClass=<fqdn to my class>

However, I get this error:
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat$AVFormatContext.(avformat.java:2249)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:346)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:340)

I also tried to build an uber jar and checked that avutil.class actually resided in the jar. Same error.
I run Debian Squeeze kernel 3.2.0.

Any idea, anyone?

@saudet
Copy link
Member

saudet commented Mar 29, 2015 via email

@yngvesl
Copy link
Author

yngvesl commented Mar 30, 2015

The cause of that Error seems to be null.

@ShihabSoft
Copy link

It can't be a null error.
As per your stack trace it is showing that NoClassDefFoundError.
It means the class avutil is not found in the package org.bytedeco.javacpp

So make sure that your dependancies are in the correct place in Android it
is libs.
That means put all additional *.jar to libs folder when you are Eclipse
Android SDK.

And in Android Studio also they are same I think so.

Hope it helps,
ShihabSoft
On Mar 30, 2015 6:52 PM, "Yngve Sneen Lindal" [email protected]
wrote:

The cause of that Error seems to be null.

Reply to this email directly or view it on GitHub
#109 (comment).

@saudet
Copy link
Member

saudet commented Mar 30, 2015

Let's see, it's probably caused by an old version of glibc: bytedeco/javacpp-presets#22
If that's the case, a rebuild on your version of Linux should fix that.

@yngvesl
Copy link
Author

yngvesl commented Mar 30, 2015

Aha, that seems probable. I will upgrade and come back if I'm still stuck. Thank you very much!

ShihabSoft; the Error object and its cause are two different objects, so an Error object can very well have a null cause. And this hasn't anything to do with either Eclipse nor Android; it's a dynamic linking version mismatch, if the hypothesis is correct.

@ShihabSoft
Copy link

Hey Lindal,

If so are you getting a null pointer exception not so ha.

You are getting a NoClassDefFoundError.

And you are getting this stacktrace ,

java.lang.NoClassDefFoundError: Could not initialize class
org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat$AVFormatContext.(avformat.java:2249)
at
org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:346)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:340)

Scenario

At the time of initialization of avutil class.

The org.bytedeco.javacpp.Loader tried to load the class avformat class in
which the sub class named AVFormatContext makes the error NoClassDefFound
error.

Try looking for the avformat class and make sure the avformat is the latest
one that contains the sub class AVFormatContext.

Check for some new classes are introduced in 0.10 version to the prior
version.

It all happens when the grabber.startUnsafe function is called.

That may resolves your problem.

And u r here to solve your problem.
So its ur need.
So please be polite.

And we all together will find a better solution.

Hope u understand,
ShihabSoft

Aha, that seems probable. I will upgrade and come back if I'm still stuck.
Thank you very much!

ShihabSoft; the Error object and its cause are two different objects, so an
Error object can very well have a null cause. And this hasn't anything to
do with either Eclipse nor Android; it's a dynamic linking version
mismatch, if the hypothesis is correct.

Reply to this email directly or view it on GitHub
#109 (comment).

@ideastorm
Copy link

In case another Windows users runs into this:

I was seeing the exact same error and stack trace (from FFmpegFrameGrabber on). Debugging the Loader.load method revealed that there was an unsatisfied link error that didn't show up in the error log:

no jniavutil in java.library.path

I also found that adding a dependency on the org.bytedeco.javacpp-presets:ffmpeg artifact specific to my platform fixed it. I also had to add the org.bytedeco.javacpp-presets:opencv artifact.

In retrospect, I just re-read the instructions, and found I'd missed a step. Oops.

Additionally, we need to either set the platform.dependency system property (via the -D command line option) to something like android-arm, or set the platform.dependencies one to true to get all the binaries for Linux, Mac OS X, and Windows. On build systems where this does not work, we need to add the platform-specific artifacts manually.

@yngvesl
Copy link
Author

yngvesl commented Apr 6, 2015

Thank you very much, @saudet. That did the trick!

@saudet
Copy link
Member

saudet commented Apr 7, 2015

Ok, good! Marking as a duplicate of: bytedeco/javacpp-presets#22

@saudet saudet closed this as completed Apr 7, 2015
@saudet
Copy link
Member

saudet commented Apr 7, 2015

@ideastorm I've emphasized the last sentence in the README.md file to draw attention. Thanks for the feedback!

@MarcoVCiotola
Copy link

@ideastorm or @saudet, I'm getting the same error, could any of you guys please explain me how to add the artifacts manually? (I'm using windows, maven and IntelliJ). Thanks a lot in advance!.

@saudet
Copy link
Member

saudet commented Jul 14, 2015

@MarcoVCiotola You're under Windows, so GLIBC isn't the issue here. Could you use Dependency Walker on the DLLs and report what seems to be the problem? Thanks!

@MarcoVCiotola
Copy link

Hi @saudet , I've run Dependency Walker on avutil.dll and it says that API-MS-WIN-SERVICE-PRIVATE-L1-1-1.DLL, API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-1.DLL and API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-1.DLL are missing; but I google those libraries and found that some peolple had the same issue, but most of the times they were not related to those libraries and that the problem lies entirely elsewhere. In this case @ideastorm solve it by adding the artifacts manually, my problem is that I don't know hot to do it :(. If you could be so kind to explain me how to do it I really apreciate it a lot!!. Thanks again for responding even though the issue is closed (I've realized after I posted the question)

@saudet
Copy link
Member

saudet commented Jul 14, 2015

That sounds like Dependency Walker is failing as well... The missing dependency is something else.

@somesaba
Copy link

somesaba commented May 8, 2016

Hi guys, I am getting the same error with a Raspberry Pi. I'm not exactly sure how to add the platform-specific artifacts manually. I added the org.bytedeco.javacpp-presets:ffmpeg and org.bytedeco.javacpp-presets:opencv to no avail.

@xswkama
Copy link

xswkama commented Mar 22, 2018

增加下面的包

    <dependency>
        <groupId>org.bytedeco.javacpp-presets</groupId>
        <artifactId>opencv-platform</artifactId>
        <version>3.4.0-1.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/ffmpeg-platform -->
    <dependency>
        <groupId>org.bytedeco.javacpp-presets</groupId>
        <artifactId>ffmpeg-platform</artifactId>
        <version>3.4.1-1.4</version>
    </dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants