我正在使用Windows 7,Eclipse 4.2.1和(尝试使用)MigLayout 4.0。
我已经下载了miglayout-4.0-swing.jar,将其添加到我的类路径中并在Groovy Console中成功运行以下脚本:
import groovy.swing.SwingBuilder
import groovy.swing.factory.LayoutFactory
import javax.swing.WindowConstants as WC
import net.miginfocom.swing.MigLayout
def swing = new SwingBuilder()
swing.registerBeanFactory('migLayout', MigLayout)
swing.build {
frame(id: 'eventScrollPanel', pack: true, show: true,
defaultCloseOperation: WC.EXIT_ON_CLOSE) {
migLayout(layoutConstraints: "fill, debug", columnConstraints: "",
rowConstraints: "")
panel() {
label(text: "test")
}
}
}
在Eclipse中,我已将外部jar文件添加到我的JDK并检查它是否出现在Project =>中属性=> Java Build Path => Libraries选项卡=> JRE系统库[jdk1.7.0_09]。但是,脚本失败并出现以下错误:
Caught: java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
at net.miginfocom.layout.UnitValue.<init>(Unknown Source)
at net.miginfocom.layout.UnitValue.<clinit>(Unknown Source)
at net.miginfocom.layout.PlatformDefaults.<clinit>(Unknown Source)
at net.miginfocom.swing.MigLayout.<init>(Unknown Source)
at net.miginfocom.swing.MigLayout.<init>(Unknown Source)
at MigLayoutExamples$_run_closure1_closure2.doCall(MigLayoutExamples.groovy:12)
at MigLayoutExamples$_run_closure1_closure2.doCall(MigLayoutExamples.groovy)
at MigLayoutExamples$_run_closure1.doCall(MigLayoutExamples.groovy:10)
at MigLayoutExamples$_run_closure1.doCall(MigLayoutExamples.groovy)
at MigLayoutExamples.run(MigLayoutExamples.groovy:9)
Caused by: java.lang.NullPointerException
at net.miginfocom.layout.LayoutUtil.hasBeans(Unknown Source)
at net.miginfocom.layout.LayoutUtil.<clinit>(Unknown Source)
... 10 more
此外,Eclipse强调脚本第12行开头的migLayout引用,即Eclipse canot解析引用。
感谢所有人的帮助。
答案 0 :(得分:2)
看起来line是罪魁祸首。
LayoutUtil.class.getClassLoader().loadClass("java.beans.Beans");
最新的jar是4.2,这个问题似乎已经用try-catch
块修复了
尝试使用这些罐子。它们可从Maven回购中获得。 http://mvnrepository.com/artifact/com.miglayout/miglayout-swing/4.2
http://mvnrepository.com/artifact/com.miglayout/miglayout-core/4.2