类测试(在未命名的模块中 @0x33f888ab)无法访问com.sun.media.sound.fft(在模块java.desktop中)
我想使用Musicg分析音频指纹。
但是我在Musicg库中遇到了错误。
IllegalAccessError: class Test
(in unnamed module @0x33f88ab) cannot access class com.sun.media.sound.FFT
(in module java.desktop)
because module java.desktop does not export com.sun.media.sound to unnamed module @0x33f88ab
我应该怎么办?
环境
- Kotlin
- JDK 17(可用降级)
- Musicg 1.4.2.2
我的代码
fun main(args: Array<String>) {
FFT(10, 20)
}
在 fft(10,20)
中得到了例外
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
com.sun
及其子包装不是公共Java API的一部分。他们实现了一些标准的Java API,但是您不应该直接参考它们。 (它们可能会更改和/或在JVM版本之间重命名或删除,而非Sun/Oracle JVM可能根本不会有它们。)在大多数情况下,您应该访问公共API类(例如,
javax.sound
)。 这些可以使用sun。
( 使用那些内部实施类别的人对停止没有什么,因此一些开发人员陷入了不良习惯。但是Java 9添加了A 模块系统,限制了访问它们。您看到的错误消息是结果。
详细信息在 jep 260 。目的是,所有受到限制的关键API都会有公共API。但是,根据论坛页面,这项工作尚未完成,因此有一些内部API,目前尚无公共等效物。
FFT
看起来就像被忽略的类之一。恐怕,我看不到直接替代。您可以使用第三方库吗? 这个问题提供了一些选择。com.sun
and its sub-packages are not part of the public Java API. They implement some standard Java APIs, but you shouldn't refer to them directly. (They're likely to change and/or be renamed or removed between JVM releases, and non-Sun/Oracle JVMs probably won't have them at all.)In most cases you should access the public API classes (e.g. in
javax.sound
) instead. (Those may usesun.*
/com.sun.*
/etc. classes internally as needed, but that's merely an implementation detail.)In early versions of Java, there was nothing to stop people using those internal implementation classes, and so some developers got into bad habits. But Java 9 added a module system, which restricts access to them. The error message you see is a result of that.
The details are in JEP 260. The intent was that there would be public APIs for all of the critical APIs that were being restricted. However, according to this Oracle forum page, the work wasn't completed, and so there are some internal APIs for which no public equivalent exists yet.
FFT
looks like one of those classes that has been overlooked. I can't see a direct replacement for it, I'm afraid. Is there a third-party library you can use? This question gives some options.