本文介绍了Scala中的Java AWT:(AWT-EventQueue-0)java.lang.NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use java awt in scala to make a simple desktop application. I have been working on it for some days without any problem, until I didn't touch it for 2 days and when I came back, I get a java.lang.NoClassDefFoundError exception. It was working fine before, but now even the simplest of code gives me this error.

https://github.com/aganm/NoClassDefFoundError

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

它可以编译,但是出现这个异常

It compiles, but I get this exception

[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重现该问题.另外,即使在使用SBT 1.3.0的情况下将fork := true添加到build.sbt文件中时,我也没有重现该问题.您可以使用这些选项中的任何一种作为解决方法.

I suspect a SBT bug. I can reproduce the issue with SBT 1.3.0, but not with SBT 1.2.8. Also I do not reproduce the issue when I add fork := true into the build.sbt file even when using SBT 1.3.0. You can use any of those options as a workaround.

我将问题报告为 SBT 1.3.0出现奇怪的NoClassDefFoundError错误,并且现在已在SBT 1.3.2中修复.

I have reported the issue as Strange NoClassDefFoundError error with SBT 1.3.0 and it is now fixed in SBT 1.3.2.

1.3.0的新功能似乎是在进程类加载中-但是,所描述的值似乎都不能解决该问题,因此,我不确定它是否真的相关.

The 1.3.0 new functionality seems to be In process class loading - however none of the values described seems to fix the issue, therefore I am not sure if it really related.

这篇关于Scala中的Java AWT:(AWT-EventQueue-0)java.lang.NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 11:48