Repository navigation
Description
Hello,
First off, thank you very much for authoring this package. Tremendous job.
I'm working on a particularly tricky piece of code that involves using the java AWT. I'm currently getting an error while trying to read a file using the javax.imageio.ImageIO class. Here's the offending code:
var file = java.newInstanceSync("java.io.File", path);
var image = java.callStaticMethodSync("javax.imageio.ImageIO", "read", file);The error thrown is:
Error: Error running static method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
Caused by: java.lang.InternalError: Can't start the AWT because Java was started on the first thread. Make sure StartOnFirstThread is not specified in your application's Info.plist or on the command line
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1724)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
at java.security.AccessController.doPrivileged(Native Method)
at sun.java2d.Disposer.(Disposer.java:41)
at javax.imageio.stream.FileImageInputStream.(FileImageInputStream.java:82)
at javax.imageio.stream.FileImageInputStream.(FileImageInputStream.java:57)
at com.sun.imageio.spi.FileImageInputStreamSpi.createInputStreamInstance(FileImageInputStreamSpi.java:37)
at javax.imageio.ImageIO.createImageInputStream(ImageIO.java:331)
at javax.imageio.ImageIO.read(ImageIO.java:1278)
... 4 more
Any idea how I might be able to get around this?
Thanks in advance!
Activity
joeferner commentedon Feb 9, 2012
Sounds like an issue with the Apple JVM: [http://lists.apple.com/archives/java-dev/2005/Mar/msg00506.html]. It looks like setting java.awt.headless to true could fix it. You can try setting the property using java.lang.System.setProperty.
I also just added the ability to add JVM start options. You need to call this before the VM gets created so preferably right after the first require statement for node-java (see the unit test testHelper.js file for an example).
If you don't mind could you also run "nodeunit test" to make sure they work. I've added the above awt calls to a test. The awt calls work fine on ubuntu but I want to make sure it works on a mac as well. If everything checks out I'll make a new release of node-java.
bcelenza commentedon Feb 9, 2012
This appears to have solved it. All tests passed in node unit, and my code is returning the proper image width/height in node.js after a call out to ImageIO. Thanks for the quick turn around!
Update commons-lang for better handling of no args passed for varargs…