gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:25:27 24 4
gpt4 key购买 nike

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

javac -cp "c:\projects\java\currentProject" --module-path "c:\Program Files\Java\javafx-sdk-11.0.1\lib" --add-modules=javafx.controls,javafx.fxml Alert.java Main.java

虽然 Alert.java 编译得很好,但 Main.java 无法导入 Alert 类,并在“导入 Alert”时出现错误。我尝试了“导入 Alert.Alert”和“导入 currentProject.Alert”,但仍然不起作用。另外,我在每个文件的开头声明了包“package currentProject”,但它仍然给出错误。

我应该做什么才能让它运行?我已经在所有可用的 IDE 上安装 JavaFX 失败了,所以我不会使用 Atom 之外的 IDE。但如何正确编译呢?

更多信息-

文件结构:

c->projects->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 ,如果您对某些阅读感兴趣,this是来自 Oracle 博客的关于 JavaFX 计划的链接。

祝你好运!

关于javac 在当前文件夹中找不到另一个已编译的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53988219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com