1

I'm trying to save an image to my file system as noted on the javafx image ops page: http://docs.oracle.com/javafx/2/image_ops/jfxpub-image_ops.htm but I keep getting this exception error:

java[80783:707] [JRSAppKitAWT markAppIsDaemon]: Process manager already initialized: can't fully enable headless mode.

This stackoverflow question sort of helped JavaFX screencapture headless exception on OSX but I am still stuck on saving an image.

Any way I can go about saving an image?

This is how I am currently doing it:

File outFileImage = new File(imageUrl);

Toolkit tk = java.awt.Toolkit.getDefaultToolkit().getDefaultToolkit();
try {
    ImageIO.write(SwingFXUtils.fromFXImage(image, null), ".png", outFileImage);
} catch (Exception e) {
    log.log(Level.WARNING, "Image not saved to disk", e);
}


EDIT

I attempted running Java 8 to see if the problem would be resolved but I kept getting JavaFX FXML errors:

javafx.fxml.LoadException: Root hasn't been set. Use method setRoot() before load.
/Users/jonathan/Projects/Dominion/target/classes/dominion/application/controller/main_overview_tab.fxml:13

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2613)
at javafx.fxml.FXMLLoader.access$100(FXMLLoader.java:104)
at javafx.fxml.FXMLLoader$RootElement.constructValue(FXMLLoader.java:1320)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at dominion.application.controller.MainOverviewTab.initView(MainOverviewTab.java:64)


EDIT

I have posted this JavaFX FXML loading problem into another question found here: Root hasn't been set Error with Java 8 Eclipse

Community
  • 1
  • 1
j will
  • 3,747
  • 11
  • 41
  • 64

1 Answers1

2

In a comment on RT-20784 Mac: Headless environment issue, MacOSX, which is related to the warning message you have pasted into your question, a developer notes:

This indeed requires fixes in JDK. We don't have plans to back port these specific changes to 7uX releases because they are somewhat risky, and we don't want to destabilize the 7uX branch. As Steve suggests, please move to 8.

AFAIK, apart from the fact that FX forces the AWT to run in the headless mode, nothing else changes or breaks because of this. So you may assume that the warning printed out to the console is the only side-effect of the missing changes. As long as you don't need to use AWT/Swing in your application, you should be safe.

So perhaps your best course of action is to try Java 8 and see if you still have any issues.

Update Based on Updated Question Regarding setRoot()

What build of Java 8 are you getting FXML errors? According to this Bug Report, this particular "Root hasn't been set" FXML loading error may have been fixed in JavaFX 8b121. Potentially see the related StackOverflow question on setRoot errors. The FXML loading issue is unrelated to the original question of saving an image to the file system, usually unrelated questions are best asked as new questions.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406