Java Question Building Custom Library with Java throws ClassNotFound Error

mayankrajawat

New Member
Licensed User
Longtime User
:sign0104: alert

Hi,

I've been trying to follow this youtube video to build my library for B4A : Basic4android Tutorial - Creating a library - YouTube

And once I am done with Jar and xml building and try to use that in my B4A application, it has trouble finding my Java Class while it's there.

The error it throws, is:

01-25 19:26:58.437: I/B4A(698): java.lang.NoClassDefFoundError: com.firstlib.b4a.MyClass


The point to note is that in my Java code, I am referring a third party library too, but that should pretty much be like importing other jars as discussed in the video.

I also searched this forum and found two posts discussing this, but that also led to nowhere:
1) http://www.b4x.com/forum/libraries-developers-questions/19367-java-lang-noclassdeffounderror-one-more-time.html#post111580
2) http://www.b4x.com/forum/basic4android-updates-questions/24278-preparation-new-library-b4a-call-error-what-will-next-issue.html#post140499

I have corrected my CLASSPATH and JAVA_HOME variable, to no avail.

Sorry if I have been bad at searching and fixing it, but I promise I've given enough time on this.

Any help would be deeply appreciated!
 

mayankrajawat

New Member
Licensed User
Longtime User
Thanks Erel!

I was having Java (JDK+JRE) 7 version and now I have installed v6, and that error seemed to have gone.

Now another one has popped up.

The Java project that I created in Eclipse to act as a wrapper for the third party library I am about to use, it fails to find one of the base classes of that third party library.

This question maybe slightly different, but for the sake of keeping things in the same thread, I am asking it here.

It is weird, because the same Java project has b4a's Core.jar, B4AShared.jar and android.jar inside as well as this third party library, and everything else except this third party jar's class can be found.

Any idea why this might be happening?
I am using Eclipse's "export" option to make a jar out of my Java project.
Is this way making it tough for the generated jar to find that third party class?

Thanks once again.
 

Informatix

Expert
Licensed User
Longtime User
Thanks Erel!

I was having Java (JDK+JRE) 7 version and now I have installed v6, and that error seemed to have gone.

Now another one has popped up.

The Java project that I created in Eclipse to act as a wrapper for the third party library I am about to use, it fails to find one of the base classes of that third party library.

This question maybe slightly different, but for the sake of keeping things in the same thread, I am asking it here.

It is weird, because the same Java project has b4a's Core.jar, B4AShared.jar and android.jar inside as well as this third party library, and everything else except this third party jar's class can be found.

Any idea why this might be happening?
I am using Eclipse's "export" option to make a jar out of my Java project.
Is this way making it tough for the generated jar to find that third party class?

Thanks once again.

Did you add @DependsOn(values = {"your_3rdpty_lib"}) in your Java source ?
 

mayankrajawat

New Member
Licensed User
Longtime User
Yes, I added:

1) @DependsOn(values = { "com.mylib.android" })
2) @DependsOn(values = { "MyLibJarName" })

both, before the class declaration, but it hasn't made any difference yet. :-/
 

mayankrajawat

New Member
Licensed User
Longtime User
I tried "importing" the whole jar of my third party library and it Eclipse got all the class files inside the project, and it now seems to be working.

Don't know what happened in the background, but it now works.
Will dig more.
If you have more information about the behind the scenes of this import thing, I'd love to know! :)

Now figuring how to add a custom manifest file

Thanks for all the help!
 

warwound

Expert
Licensed User
Longtime User
For some more reading on the subject take a look at my post here: http://www.b4x.com/forum/libraries-...class-not-found-3rd-party-lib.html#post148551.

That thread is very recent and has the same problem - the b4a library not being able to find a class in a (wrapped) 3rd party jar.

My post links to a much older thread where it was discussed whether to include the 3rd party jar in the compiled b4a library jar, or whether to keep the 3rd party jar external and use the @DependsOn annotation.

Martin.
 
Top