我正在开发一个基于 android 的应用程序来处理语音。我的应用程序引用了 .jar 依赖项,并且我已成功将该 jar 作为库添加到我的项目中,但是当我运行项目时,它给了我java.lang.NoClassDefFoundError: for an class file which is there in jar file 基本上是类文件抛出上述错误会在代码中导入 javax.sound.sampled 包。
我从过去几个月开始就在这方面工作,但没有找到任何解决办法。我尝试将 jar 库的源代码复制到 android studio 中,然后将 javax.sound.sampled jar 引用到它甚至尝试将 javax.sound.sampled 源代码复制到 android 中,然后按照流程附加它们,但仍然没有运气。
如果我得到以下进口的替代品会很好,因为它将解决问题
- 导入 javax.sound.sampled.AudioFileFormat;
- 导入 javax.sound.sampled.AudioFormat;
- 导入 javax.sound.sampled.AudioFileFormat.Type;
- 导入 javax.sound.sampled.AudioFormat.Encoding;
- 导入 javax.sound.sampled.AudioInputStream;
- 导入 javax.sound.sampled.AudioSystem;
- 导入 javax.sound.sampled.UnsupportedAudioFileException;
编辑:我在这里遇到问题
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;
}
它给了我 TwoEnumerationsInOne 和 configs.hasMoreElements() 给了 false 所以不能进入 while 循环。AudioFileReader.java 包含在包中
提前致谢。