Java Question Class not found in 3rd party lib

pdmccann

Member
Licensed User
Longtime User
I am writing a library for B4A and it uses another library from a third party. I was happy to get a stack trace from my library in the B4A log that said there was a class not found exception in the third-party library. If I look at the jar with 7-Zip I created and placed in Additional Libs, it is in the libs folder of the jar. Am I missing a class path entry that should be in the libraries xml from the doclet, or somewhere else?

Stack trace:
button clicked
exception on create reader: java.lang.NoClassDefFoundError: IDTech.MSR.uniMag.uniMagReaderHelper
at IDTech.MSR.uniMag.uniMagReader.<init>(uniMagReader .java:18)
at com.dsi.b4a.epay.ClientAction.createReader(ClientA ction.java:75)
at KCSoft.TestLayout.main._button1_click(main.java:31 3)
at java.lang.reflect.Method.invokeNative(Native Method)


It almost looks like B4A finds the uniMagReader in the external jar, but the uniMagReader cannot find the uniMagReaderHelper which is inside the jar. Is that a likely understanding?
 
Last edited:

warwound

Expert
Licensed User
Longtime User
This thread may be of interest: http://www.b4x.com/forum/libraries-developers-questions/17767-referncing-wrapped-libs.html.

I've found that getting Eclipse to package an additional .jar file into a compiled library is tricky.
Much easier to add the DependsOn annotation to your library class and then require that the additional .jar file be located in the B4A additional libraries folder.

This has the advantage that if the additional .jar file gets updated then it can be replaced in the B4A additional libraries folder with no need to recompile your B4A library.

Martin.
 

pdmccann

Member
Licensed User
Longtime User
Thanks for the help. I am trying suggestions.

I modified the my Eclipse project so that it does not put the 3rd party lib in the jar when it is created. I did this by un-checking the lib checkbox in the JAR File Specification dialog. I looked at the jar that was created:

C:\Program Files (x86)\Anywhere Software\Basic4android\AdditionalLibs>jar -tf NccEpayClient.jar
META-INF/MANIFEST.MF
NccEpayClient.xml
com/dsi/b4a/epay/ErrCodes.class
com/dsi/b4a/epay/TranResponse.class
com/dsi/b4a/epay/DsiParser.class
com/dsi/b4a/epay/ClientAction$TranType.class
com/dsi/b4a/epay/ClientAction.class
.classpath
.project

At the end of the NccEpayClient.xml produced by the doclet I see depends:

<dependsOn>IDTuniMagSDKAndroid</dependsOn>

In my additional lib folder I just have

01/28/2013 11:40 AM <DIR> ..
04/11/2012 04:28 PM 142,472 IDTuniMagSDKAndroid.jar
01/28/2013 11:36 AM 31,638 NccEpayClient.jar
01/28/2013 11:38 AM 10,040 NccEpayClient.xml

** Activity (main) Create, isFirst = true **


However I still get the class not found exception.

exception on create reader: java.lang.NoClassDefFoundError: IDTech.MSR.uniMag.uniMagReaderHelper


at IDTech.MSR.uniMag.uniMagReader.<init>(uniMagReader.java:18)
at com.dsi.b4a.epay.ClientAction.createReader(ClientAction.java:75)
FAILED reader

Any thoughts for me?
 

warwound

Expert
Licensed User
Longtime User
If you open the IDTuniMagSDKAndroid.jar (with say WinRAR) can you find any class files for the IDTech.MSR.uniMag.uniMagReaderHelper class?

Martin.
 

pdmccann

Member
Licensed User
Longtime User
cannot find class inside 3rd party lib

Still a mystery. I used the AbsObjectWrapper just to see if I could get past the class not found. My jar is as simple as they get:

package com.dsi.b4a.unimag;

import IDTech.MSR.uniMag.uniMagReader;
import anywheresoftware.b4a.AbsObjectWrapper;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@DependsOn(values = { "IDTuniMagSDKAndroid" })
@ShortName("uniMagReader")
@Version(0.01f)
public class unimagWrapper extends AbsObjectWrapper<IDTech.MSR.uniMag.uniMagReader> {
public void initialize(BA pBA) {
setObject(new uniMagReader(null, pBA.context));
}
}

I declare a uniMagReader in Sub Globals and call initialize in the Activity_Create. The log shows:

** Activity (main) Create, isFirst = true **


main_activity_create (java line: 230)


java.lang.NoClassDefFoundError: IDTech.MSR.uniMag.uniMagReaderHelper
at IDTech.MSR.uniMag.uniMagReader.<init>(uniMagReader.java:18)
at com.dsi.b4a.unimag.unimagWrapper.initialize(unimagWrapper.java:15)
at b4a.example.main._activity_create(main.java:230)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
....

Looking at the IDTuniMagSDKAndroid.jar in Additional Libraries I clearly see UniMagReader and UniMagReaderHelper.
 

pdmccann

Member
Licensed User
Longtime User
uploaded 3rd party library

Erel, this is the third party library where the class is not found
 

Attachments

  • IDTuniMagSDKAndroid.zip
    130.6 KB · Views: 282

pdmccann

Member
Licensed User
Longtime User
Sorry for delay - this jar has classes it cannot find

Here is the third party jar file that results in the class not found error.
 

Attachments

  • IDTuniMagSDKAndroid.zip
    130.6 KB · Views: 289

pdmccann

Member
Licensed User
Longtime User
wrapper lib and xml

Here is the wrapper project and its XML file
 

Attachments

  • B4AWrapper.zip
    1.8 KB · Views: 293
Top