Question

I am using Windows 7, Eclipse 4.2.1 and (trying to use) MigLayout 4.0.

I have downloaded miglayout-4.0-swing.jar, added it to my classpath and succesfully run the following script in 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")
        }
    }
}

In Eclipse, I have added the external jar file to my JDK and checked that it appears in Project => Properties => Java Build Path => Libraries tab => JRE System Library [jdk1.7.0_09]. However, the script fails with the following error:

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

Also, the migLayout reference at the start of line 12 of the script is underlined by Eclipse, i.e. Eclipse canot resolve the reference.

All help gratefully appreciated.

Was it helpful?

Solution

Looks like this line is the culprit.

LayoutUtil.class.getClassLoader().loadClass("java.beans.Beans");

The latest jar is 4.2 where this issue seems to have been fixed with a try-catch block.
Try with these jars. They are available from Maven repo. http://mvnrepository.com/artifact/com.miglayout/miglayout-swing/4.2
http://mvnrepository.com/artifact/com.miglayout/miglayout-core/4.2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top