gpt4 book ai didi

javafx open window no effect.application launch with then throw class not found

转载 作者:行者123 更新时间:2023-12-04 03:42:03 25 4
gpt4 key购买 nike

<分区>

好的,为了启动 javafx 应用程序,我们需要启动 javafx 应用程序。然后,如果我们想添加一个新窗口,我们可以简单地执行 stageobj.show();对吧?

下面是我的代码的一部分,我尝试创建新窗口。我已经启动了我的应用程序并想从我的应用程序中调用这个新代码。

//imports all needed class

public String plugstart(){
try{Application.launch();
net.time4j.ui.javafx.CalendarPicker obj=net.time4j.ui.javafx.CalendarPicker.gregorianWithSystemDefaults();
javafx.scene.Scene scn=new javafx.scene.Scene(obj, 300, 250);
Stage stage = new Stage();
stage.setTitle("Date pick test");//scn.getChildren().add(obj);
stage.setScene(scn);
stage.show();
return "ok";}catch(Exception e){java.io.StringWriter sw = new java.io.StringWriter();
java.io.PrintWriter pw =new java.io.PrintWriter(sw);
e.printStackTrace(pw);return sw.toString();}
}

// not sure if this function is useful or not
@Override
public void start(Stage stage) {
try{Application.launch();
net.time4j.ui.javafx.CalendarPicker obj=net.time4j.ui.javafx.CalendarPicker.gregorianWithSystemDefaults();
javafx.scene.Scene scn=new javafx.scene.Scene(obj, 300, 250);
stage.setTitle("Date pick test");//scn.getChildren().add(obj);
stage.setScene(scn);
stage.show();
}catch(Exception e){}
}

证明它编译完美。

:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest>javac -cp ;D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\*;D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest *.java

D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest>

好的,有什么问题吗?它应该可以正常工作吗?遗憾的是没有。下面的图片是堆栈跟踪。 show class not found

谁有类似的经验或解决方案?

edit1,好的,所以有人问了 java 版本,我无法评论。

D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest>java-version openjdk version "15" 2020-09-15 OpenJDK Runtime Environment (build 15+36-1562) OpenJDK 64-Bit Server VM (build 15+36-1562, mixedmode, sharing)

jvm 提示 Testdategui.class是的,这是我应该有这个新阶段的类(class)。注意它实际上已经执行了第 7 行,但仍然提示找不到类。@@

非常感谢

编辑2,基于亲爱的 jetspiking 建议。1,我试图确保没有两次启动应用程序。删除了启动废话。2,确保它实际上是使用javafx线程和javafx.application.Platform.runLater

Walah,猜猜发生了什么?它实际上返回了“ok”。但是,ui 不在那里。(呜咽)

新功能状态>

public String plugstart(){
try{
javafx.application.Platform.runLater(new Runnable(){public void run(){
net.time4j.ui.javafx.CalendarPicker obj=net.time4j.ui.javafx.CalendarPicker.gregorianWithSystemDefaults();
javafx.scene.Scene scn=new javafx.scene.Scene(obj, 300, 250);
Stage stage = new Stage();
stage.setTitle("Date pick test");//scn.getChildren().add(obj);
stage.setScene(scn);
stage.show();
}});
return "ok";}catch(Exception e){java.io.StringWriter sw = new java.io.StringWriter();
java.io.PrintWriter pw =new java.io.PrintWriter(sw);
e.printStackTrace(pw);return sw.toString();}
}

好的,我尝试了解决方案并对其进行了调整。我认为它应该可以工作,但是我有 classnotfound 异常。

我认为这是我自己的类路径设置问题,不是答案问题,所以我会接受答案。

对于那些好奇的人,现在我有这个新错误。如果我使用“全新类”。

:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide>java -cp %newcp%--module-path %newcp% --add-modules=all-modules Testdategui
Error: Could not find or load main class ;D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide\*;D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide
Caused by: java.lang.ClassNotFoundException: ;D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide\*;D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide

D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide>

reference src,应该可以吗?但是我这边有问题

import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.application.Application;
public class Testdategui extends Application
{

@Override
public void start(Stage primaryStage) throws Exception {
// Launch all your JavaFX code and methods from inside this Entry Point function.
Stage stage = new Stage();
Scene scene = new Scene(net.time4j.ui.javafx.CalendarPicker.gregorianWithSystemDefaults());
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch(args);
}

}

编辑 4,抱歉,模块路径中没有空格,但出现新错误。我会尝试自己搜索答案

java -cp %newcp% --module-path %newcp% --add-modules=all-modules TestdateguiError occurred during initialization of boot layerjava.nio.file.InvalidPathException: Illegal char <*> at index 104: D:\Coding\JavaSourceCode\plugin\userareaplugin\otherpartylibderived\time4jtest\test3basedonSO_menoguide*

最后的编辑,worked.java -cp %newcp% --module-path %cd% --add-modules ALL-MODULE-PATH Demo

谢谢。

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