0

I am developing an android based app which process speech. My app references a .jar dependency and I have successfully added that jar as a library in my project but as I run the project it gives me java.lang.NoClassDefFoundError: for an class file which is there in jar file Basically the class file which throwing the above error imports javax.sound.sampled packages in the code.

I am working on this part since last couple of months now but didn't found any way out of this. I have tried copying the source code of jar library into android studio and then referencing javax.sound.sampled jar to it even tried copying javax.sound.sampled source code into android and then attaching them as per flow but still no luck.

It would be nice if I get alternatives for below imports, as it will solve the issue

  1. import javax.sound.sampled.AudioFileFormat;
  2. import javax.sound.sampled.AudioFormat;
  3. import javax.sound.sampled.AudioFileFormat.Type;
  4. import javax.sound.sampled.AudioFormat.Encoding;
  5. import javax.sound.sampled.AudioInputStream;
  6. import javax.sound.sampled.AudioSystem;
  7. import javax.sound.sampled.UnsupportedAudioFileException;

Edit: I am facing problem here

String strFullName = "com/example/packagename/AudioFileReader.class";
Enumeration<?> configs = null;   
    try {
                    configs =  Service.class.getClassLoader().getSystemResources("strFullName");
    } catch (Throwable e) {

    }
if (configs != null) {
        while (configs.hasMoreElements()) {
URL configFileUrl = (URL) configs.nextElement();

            InputStream input = null;
            try {
                input = configFileUrl.openStream();
            } catch (Throwable e2) {


            }
            if (input != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(input));
                try {
                    for (String strLine = reader.readLine(); strLine != null; strLine = reader.readLine()) {
                        strLine = strLine.trim();
                        int nPos = strLine.indexOf(35);
                        if (nPos >= 0) {
                            strLine = strLine.substring(0, nPos);
                        }
                        if (strLine.length() > 0) {
                            providers.add(strLine);
                        }
                    }
                } catch (Throwable e22) {

                }
            }
        }
    }
    Iterator<String> iterator = providers.iterator();

    return iterator;
}

It gives me TwoEnumerationsInOne and configs.hasMoreElements() gives false so not able to go into while loop. AudioFileReader.java is included in the package

Thanks in advance.

Prafull
  • 31
  • 8
  • 1
    javax.sound could not be used in android projects, you have to look for another sound library. – Opiatefuchs Apr 11 '16 at 07:30
  • @Opiatefuchs Thanks, Can you guide me to any of the sound library available for android except android's built-in library as I tried using that but that do not serves my target goal. – Prafull Apr 11 '16 at 15:39
  • maybe this one, there are a few libs out there, just google about: https://github.com/LeffelMania/android-midi-lib – Opiatefuchs Apr 11 '16 at 16:48
  • @Opiatefuchs Thanks, I will look at it and just a normal question do I need to alter my code as per your suggested library for my required packages mentioned in the question? – Prafull Apr 11 '16 at 18:45
  • @Opiatefuchs sorry I didn't found required packages in library you referred. :( – Prafull Apr 11 '16 at 19:34
  • you just need to download the zip. You will not find the packages that you have listed in your question, it´s a standalone library. – Opiatefuchs Apr 12 '16 at 05:31
  • @Opiatefuchs Ohh Thanks man :) just a small silly question can you guide me how can I use this downloaded zip library in my project? – Prafull Apr 12 '16 at 16:14
  • As this seems to have no jar file or is able to include into gradle, I think you have to copy that into your project as usual classes. I guess you have to do a little workaround here. – Opiatefuchs Apr 13 '16 at 05:42
  • @Opiatefuchs no luck with your referred library :( – Prafull Apr 15 '16 at 14:28
  • sorry for this. I know it´s hard with sound libraries and I can´t understand why javax.sound is not a part of android. I´m taking a look in these days, if I find another solution, I´ll come back.. – Opiatefuchs Apr 15 '16 at 16:26
  • @Opiatefuchs thank you man :) sure I am working and looking around too on this please share any library if you come across. Thanks again :) – Prafull Apr 15 '16 at 19:31
  • I´m sorry, found nothing else but this library. But we can go through and check where the problem is. What doesn´t work if you try this lib? – Opiatefuchs Apr 17 '16 at 18:25
  • @Opiatefuchs I can't find the methods I want to use in my project in this library – Prafull Apr 19 '16 at 09:10
  • so what want you do? – Opiatefuchs Apr 19 '16 at 09:19
  • @Opiatefuchs I have updated my answer about where the actual problem is. – Prafull Apr 19 '16 at 16:35
  • @Opiatefuchs I have posted a new complete question about this issue here http://stackoverflow.com/questions/36725291/enumerationurl-configs-hasmoreelements-gives-false – Prafull Apr 19 '16 at 17:22

0 Answers0