我正在将我的旧Java应用程序从swing转换为javafx,我遇到了一个问题.
我正在使用以下代码来捕获屏幕截图:
public ScreenCapper() {
ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
gs = ge.getScreenDevices();
try {
robot = new Robot(gs[gs.length-1]);
} catch (AWTException e) {
LOGGER.getInstance().ERROR("Error creating screenshot robot instance!");
}
}
public Color capture() {
Rectangle bounds;
mode = gs[0].getDisplayMode();
bounds = new Rectangle(0, 0, mode.getWidth(), mode.getHeight());
//......
}
Run Code Online (Sandbox Code Playgroud)
这在Windows下运行应用程序时工作正常.但是,在OSX下运行时会出现以下异常:
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.awt.HeadlessException
at sun.java2d.HeadlessGraphicsEnvironment.getScreenDevices(HeadlessGraphicsEnvironment.java:72)
at be.beeles_place.roggbiv.utils.ScreenCapper.<init>(ScreenCapper.java:33)
at be.beeles_place.roggbiv.modes.AverageColorMode.start(AverageColorMode.java:31) …Run Code Online (Sandbox Code Playgroud)