javac在当前文件夹中找不到另一个已编译的类



我使用的是OpenJDK11。我在当前文件夹中有两个Java文件,它们应该一起运行,成为一个JavaFX应用程序。其中一个名为Main.java,运行主窗口。另一个是Alert.java,它应该运行一个作为警报类型的备用窗口。现在,我运行了以下命令:

javac -cp "c:projectsjavacurrentProject" --module-path "c:Program FilesJavajavafx-sdk-11.0.1lib" --add-modules=javafx.controls,javafx.fxml Alert.java Main.java

虽然Alert.java编译得很好,但Main.java无法导入Alert类,并在"导入Alert"时出错。我尝试过"import Alert.Alert"one_answers"import currentProject.Alert",但仍然没有成功。此外,我在每个文件的开头声明了包"packagecurrentProject",但它仍然给出了一个错误。

我该怎么办才能让它运转起来?我已经在所有可用的IDE上安装JavaFX失败了,所以我不打算使用Atom以外的IDE。但是我该如何正确地编译它呢?

更多信息-

文件结构:

c->项目->java->economicManager->(Alert.java、Main.java、financialManager.fxml、Alert.fxml、Alert.class、Alert$Controller.class和Main.class[以前编译的版本])

Alert.java:

package financialManager;
import javafx.stage.Stage;
import javafx.stage.Modality;
import javafx.scene.Scene;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import java.util.Map;
public class Alert {
public Stage stage;
private Controler_Class controler;
public Alert(Parent root) {
Controler_Class clas = new Controler_Class(root);
this.controler = clas;
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("financial report");
stage.setScene(scene);
this.stage = stage;
stage.showAndWait();
}
private class Controler_Class{
Parent root;
public Controler_Class(Parent root){
}
}
}

Main.java:

package financialManager;
import Alert;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.Parent;
import javafx.scene.control.ListView;
import javafx.scene.control.SplitPane;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import java.util.Map;
public class Main extends Application{
@Override
public void start(Stage stage) throws Exception{
final int width = 300;
final int height = 450;
stage.setTitle("hello mofos");
FXMLLoader loader = new FXMLLoader(getClass().getResource("financialManager.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, width, height);
Map<String, Object> mapper = loader.getNamespace();
AnchorPane pane = (AnchorPane) mapper.get("splitpane1_anchorpane");
if(pane != null)
SplitPane.setResizableWithParent(pane, false);
else
System.out.println("it's null you idiot!");
Button btn = (Button) mapper.get("economicReport");
btn.setOnMouseClicked((event) -> {
FXMLLoader loader2 = new FXMLLoader(getClass().getResource("alert.fxml"));
Parent parent = loader2.load();
Alert alert = new Alert(parent);
});
/*
ChangeListener<Number> stageSizeListener = (observable, oldValue, newValue) ->
pane.setDividerPositions(0.20219435736677116);
stage.widthProperty().addListener(stageSizeListener);
stage.heightProperty().addListener(stageSizeListener);
*/
stage.setScene(scene);
stage.show();
}
public static void main(String[] args){
launch();
}
}

我发现您错误地导入了Alert类。您的程序包是financialManager,因此您应该在导入行中使用它,如下所示:

import financialManager.Alert;

关于您在IDE方面的问题,几天前,我让JavaFX在OpenJDK 11上与Eclipse和IntelliJ配合良好,没有任何问题-对于OpenJDK,您需要OpenJFX,如果您对一些阅读感兴趣,这是Oracle博客中关于他们JavaFX计划的链接。

祝你好运!

相关内容

最新更新