gpt4 book ai didi

scala 中的 Java AWT : (AWT-EventQueue-0) java. lang.NoClassDefFoundError

转载 作者:行者123 更新时间:2023-11-29 04:06:58 32 4
gpt4 key购买 nike

我正在尝试在 scala 中使用 java awt 来制作一个简单的桌面应用程序。我已经在它上面工作了几天,没有任何问题,直到我有 2 天没有碰它,当我回来时,我得到一个 java.lang.NoClassDefFoundError 异常。之前它工作正常,但现在即使是最简单的代码也会给我这个错误。

https://github.com/aganm/NoClassDefFoundError

Main.scala

import java.awt.{EventQueue}

class Bar(val bar: Int) {
}

object Main {

def main(args: Array[String]) {

EventQueue.invokeLater(() => {
val b = new Bar(20)
println(b.bar)
});

}

}

我用 sbt 运行它

sbt run

它编译,但我得到这个异常

[error] (AWT-EventQueue-0) java.lang.NoClassDefFoundError: Bar
[error] java.lang.NoClassDefFoundError: Bar
[error] at Main$.$anonfun$main$1(Main.scala:11)
[error] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
[error] oats / Cat java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
[error] at java.awt.EventQueue.access$500(EventQueue.java:97)
[error] at java.awt.EventQueue$3.run(EventQueue.java:709)
[error] at java.awt.EventQueue$3.run(EventQueue.java:703)
[error] at java.security.AccessController.doPrivileged(Native Method)
[error] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
[error] at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
[error] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
[error] at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
[error] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
[error] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
[error] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
[error] at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
[error] Caused by: java.lang.ClassNotFoundException: Bar
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error] at Main$.$anonfun$main$1(Main.scala:11)
[error] at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
[error] at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
[error] at java.awt.EventQueue.access$500(EventQueue.java:97)
[error] at java.awt.EventQueue$3.run(EventQueue.java:709)
[error] at java.awt.EventQueue$3.run(EventQueue.java:703)
[error] at java.security.AccessController.doPrivileged(Native Method)
[error] at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
[error] at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
[error] at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
[error] at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
[error] at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
[error] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
[error] at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
[error] at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
[error] stack trace is suppressed; run last Compile / bgRun for the full output

我做错了什么?

最佳答案

我怀疑是 SBT 错误。我可以使用 SBT 1.3.0 重现该问题,但不能使用 SBT 1.2.8。此外,当我将 fork := true 添加到 build.sbt 文件时,即使使用 SBT 1.3.0,我也不会重现该问题。您可以使用这些选项中的任何一个作为解决方法。

我已将该问题报告为 Strange NoClassDefFoundError error with SBT 1.3.0它现在已在 SBT 1.3.2 中修复。

1.3.0 的新功能好像是In process class loading - 然而,所描述的值似乎都无法解决问题,因此我不确定它是否真的相关。

关于scala 中的 Java AWT : (AWT-EventQueue-0) java. lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57960185/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com