Problem Creating Library i keep getting "java.lang.NoClassDefFoundError:" ERROR

abdulla

Member
Licensed User
Longtime User
i am trying to create a B4A Library for a well known audio codec, the Speex Codec its also called Jspeex, this library already available in JAVA on the net and its also been used in some android software successfully such as Ipox5 and many others on google play market and its available its class folder and as JAR , So i tried for almost two weeks to create create one some api just to initialize the encoder for speex which initialize the codec , i created the class and attached reference libraries as suggested for B4A but I KEEP GETTING COMPILER errors ALL the time , my syntax as i believe all correct , once i try to export to Jar i get errors , once i try to create JAVADOC i get WARNINGS , BUT even though Both the JAR AND XML file get created , so i added them into B4A New Library folder (folder i created for B4A) THEN I added the library to B4A project in the process global to create an instance of it only without even using the api, but i keep getting an error every time i run project , i connected my galaxy s2 through USB , and once the app starts running for 5 seconds it just CRASHES WITH "The application sptest(process.com.sp.test has stopped unexpectedly.Please try again".

this is the source for the java class :


import org.xiph.speex.SpeexEncoder;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@Permissions(values = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.RECORD_AUDIO"})
@ShortName("speexen")
@Version(1.03f)
public class speextest1 {




int mode; // wide band
int sampleRate;
int channels1;
int quality; // high quality
byte packet;
int packetlength;
boolean initstatus;
public Boolean IsInitialized = false;
public final SpeexEncoder enc = new SpeexEncoder();



public void encinit(int mode, int quality, int sampleRate,
int channels) {


try
{
enc.getSampleRate();

//* enc.init(mode, quality, sampleRate,channels);

if (enc.init(mode, quality, sampleRate,channels))
{
IsInitialized = true;
}

}





catch (Exception e)
{
e.printStackTrace();
}


}

----------------------------------------------------
and this is the source of my B4A PROJECT , nothing but decalaration forthe library

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim sp As speexen
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub one
'sp.encinit(0, 8000, 1, 0)
End Sub



}

-------------------------------------------
This is the Logcat i get when i run the project in B4A

LogCat connected to: 304D09173118252F
--------- beginning of /dev/log/main


--------- beginning of /dev/log/system
main_process_globals (java line: 254)


java.lang.NoClassDefFoundError: org.xiph.speex.SpeexEncoder
at com.speextest1.speextest1.<init>(speextest1.java:24)
at com.sp.test.main._process_globals(main.java:254)
at com.sp.test.main.initializeProcessGlobals(main.java:229)
at com.sp.test.main.afterFirstLayout(main.java:80)
at com.sp.test.main.access$100(main.java:16)
at com.sp.test.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)


-------------------------------------------------


I WOULD LIKE TO MAKE I NOTE THAT LINE 24 Mentioned in LOGCAT of the java class is this:

public final SpeexEncoder enc = new SpeexEncoder();

------------------------

I also have fixed all Envormental variables in windows 7 to POINT JAVA 1.6

CLASSPATH C:\Program Files\Java\jdk1.6.0_33\lib.;

path C:\Program Files\Java\jdk1.6.0_33\bin
JAVA_HOME C:\Program Files\Java\jdk1.6.0_33\bin

----------------------------------------------------------

I am not good in java or Eclipse but i have been searching all over the B4A forum for solution as well as through Google

After almost two weeks hard trying with no luck even though this library already working for Android devices as i mentioned for many software on Google play.
Speex or is it also Called JSPEEX is well known Audio Codec library it Used to reduce PCM bandWidth used with AudioRecord FROM 128 KB/SEC INTO of only less than 10 kb/sec through the network bandwidth if audio is tranmitted through network , these two links would give you the JAR archive as well as the source for the library

Speex: a free codec for free speech

Talkative
-------------------------------

I well appreciate any help.

Thanks in advance
 

abdulla

Member
Licensed User
Longtime User
Thank You Erel , i really appreciate your help , it works.


I added the following tag Line (i searched for it in the forum then i found its syntax)

@DependsOn(values = { "jspeex" })


then the following import is added by the editor once it detected the DependsOn tag:

import anywheresoftware.b4a.BA.DependsOn;



Now it does not crash any more.


Thank you Once Again:sign0060::D
 
Upvote 0

abdulla

Member
Licensed User
Longtime User
:confused:
well, its very strange, after it ran successfully for few times , i tried to rename i variable specifically int channels1; to make it int channels;

then all the sudden i am getting B4A Compiler error as follows :

Compiling code. 0.02
Compiling layouts code. 0.01
Generating R file. 0.01
Compiling generated Java code. 2.41
Convert byte code - optimized dex. Error
A referenced library is missing: jspeex



By the way i am using Eclipse to create the java library.

So i renamed back to int channels1; But no way, i am still getting .

trying to fix it i removed the library jar and added it again right-click on project name >properties>libraries>add External Jars

But i still get this strange B4A Compiler error ?

You mentioned in your reply if i have included the library jar in my own jar , How do i do that in eclipse ,

this is the java code :


import org.xiph.speex.SpeexEncoder;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
@DependsOn(values = { "jspeex" })
//@Permissions(values = { "android.permission.WRITE_EXTERNAL_STORAGE",
// "android.permission.RECORD_AUDIO" })
// Permissions must always be declared otherwise your app or library won’t work.
// Just search on the internet what permissions you need to use.
@ShortName("speexen")
@Version(1.08f)
public class speextest1 {

int mode;
int sampleRate;
int channels1;
int quality;
byte packet;
int packetlength;
public boolean initstatus = false;
public Boolean IsInitialized = false;
public SpeexEncoder enc;








public void encinit(int mode, int quality, int sampleRate, int channels) {


try
{
IsInitialized = true;
enc.init(mode, quality, sampleRate, channels);

if (enc.init(mode, quality, sampleRate, channels)) {
IsInitialized = true;
}

}

catch (Exception e) {
e.printStackTrace();

}
IsInitialized = true;
}

}




I will appreciate your help and thanks in advance
 
Upvote 0

abdulla

Member
Licensed User
Longtime User
Thanks Erel for help and advice, it works now,i really appreciate your response, i had to create new project in B4A , i used build path Option to add all the JARS including the jspeex.jar, but i had to to use the import option (when you click right-mouse on project name) then i imported the library jar from the disk location i noticed that it added the classes i needed when ever i exported the project class, but what i don't understand why the DependsOn only takes class name not the jar name . in the jspeex.jar has two defualt classes SpeexEncoder.class and SpeexDecoder.class all and other classes are inside the Jspeex.jar , the DependsOn tag only accepts one class of then , so it would accept this
@DependsOn(values = { "SpeexEncoder" })

But Not this

@DependsOn(values = { "SpeexEncoder","SpeexDecoder" })

i get this from B4A compiler

Convert byte code - optimized dex. Error
A referenced library is missing: speexdecoder


and whenever i place the jar like this.

@DependsOn(values = { "Jspeex.jar" })
the B4A Compiler prompt me for the missing jspeex
 
Upvote 0

qsrtech

Active Member
Licensed User
Longtime User
Did you ever get your library working? Can you post it the forum?
 
Upvote 0
Top