Paying basic sounds in android, fail NoClassDefFoundError

Hi people;

I think this is a really nooby error but I don’t know how to fix it… And reading in some places I’m not able get the solution (and inside processing forum, nearly all topics about sounds are on loaded sounds, I want somehing simplier if possible :sweat_smile:).

Well, I want to play sounds, but not loaded sounds, just anyone to make a warning. I tried to use the pulse:

Example
import processing.sound.*;
  int flag=1;
  float ancho = 0.05,cont =0;

  Pulse a = new Pulse(this);
  Sound s = new Sound(this);

void setup() {
  size(displayWidth, displayHeight);
  s.volume(1);
  a.width(0.05);  
}

void draw() {
  background(0);
  cont++;
  if(cont < 40)
    a.freq(3500);
  else{
    a.freq(4000);
    if (cont >=100)
      cont = 0;
   }
  if(flag == 1)
   a.play();
  else if (flag == -1)
   a.stop();  
}

 void mousePressed(){
   flag *= -1;   
 }

And it works fine in java mode, and in android mode, even exporting to AS (Android Studio), but my problem is when I want to put it in my code (in AS)…

I have imported the library (or at least I think so [copy the sound library from the exported code to AS to my AS project]), and added to my code this:

Think is not relevant
import processing.sound.*;

public class HMI_Scene extends PApplet {
[...]
    Pulse sonidoAlertas = new Pulse(this);
    Sound sonidoParaVolumen = new Sound(this);

 public void setup() {
[...]
        sonidoParaVolumen.volume(1);
        sonidoAlertas.width((float)0.05);
}
 public void draw() {
[...]
            sonidoAlertas.play();
}

The error I’m getting is:

java.lang.NoClassDefFoundError:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/jsyn/unitgen/PulseOscillator;
        at processing.sound.Pulse.<init>(Unknown Source)
        ...HMI_Scene.<init>(HMI_Scene.java:92)
        at ...HMI.onCreate(HMI.java:115)
        at android.app.Activity.performCreate(Activity.java:6320)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
        at android.os.Handler.dispatchMessage(Handler.java:111)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:5765)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.jsyn.unitgen.PulseOscillator" on path: DexPathList[[zip file "/data/app/.../base.apk"],nativeLibraryDirectories=[/data/app/.../lib/arm64, /vendor/lib64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at processing.sound.Pulse.<init>(Unknown Source) 
        at ...HMI_Scene.<init>(HMI_Scene.java:92) 
        at ...HMI.onCreate(HMI.java:115) 
        at android.app.Activity.performCreate(Activity.java:6320) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499) 
        at android.os.Handler.dispatchMessage(Handler.java:111) 
        at android.os.Looper.loop(Looper.java:207) 
        at android.app.ActivityThread.main(ActivityThread.java:5765) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
    	Suppressed: java.lang.ClassNotFoundException: com.jsyn.unitgen.PulseOscillator
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        		... 16 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
This are my dependecies from my build.gradle files:

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    api project(':...')

And well, what I really want is to make a sound to warn the user, don’t care if it is from an specific library, but I would like it not to be a loaded sound, because it would ralentize my app, in order to get this, I tried the case I have written, but I have the NoClassDefFoundError… If you, preciated reader, can help me to fix my error, or give me another solution, It will be fantastic :hugs:

OOuuuh yeah, thanks to @Hubbit200
This solved my problem too :hugs::hugs::hugs:

1 Like