1

我正在使用 Windows 7、Eclipse 4.2.1 和(尝试使用)MigLayout 4.0。

我已经下载了 miglayout-4.0-swing.jar,将其添加到我的类路径并在 Groovy 控制台中成功运行以下脚本:

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 => Properties => Java Build Path => Libraries tab => JRE System Library [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

此外,脚本第 12 行开头的 migLayout 引用由 Eclipse 加下划线,即 Eclipse 无法解析该引用。

感谢所有帮助。

4

1 回答 1

2

看起来这条线是罪魁祸首。

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

于 2012-12-03T08:24:40.987 回答