project name-JavaFX
module-info.java
module JavaFX {
requires javafx.fxml;
requires javafx.controls;
requires java.desktop;
opens sample;
}
Controller.java
package sample;
import javafx.fxml.FXML;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class Controller {
@FXML
public void handleClick(){
try{
Desktop.getDesktop().browse(new URI("http://www.javafx.com"));
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
}
}
}
Error i get : Error:(1, 1) java: module JavaFX reads package java.awt from both java.desktop and java.datatransfer
How to resolve this problem?
Just had the same problem. According to This IDEA Support Thread it may be somewhat of a red herring error message. It looks like the module file is actually correct (even though intellij takes you there), yet the problem is actually because IDEA adds a compiler parameter with all the alt-enter's we did (we all do it...).
If you navigate to settings -> Build, execution, deployment -> compiler -> Java compiler and look towards the bottom, you will see that its has added and --exports of awt from datatransfer to the module, as shown in the image below:
Simple remove this and awt is only read from desktop.
I understand this problem isnt the most in depth explanation of whats going on, so if anyone would like to elaborate it would be mush appriciated.