我创建了一个简单的JavaFX应用程序来猜测一个数字:
Main.java
package pl.diakowski.guessingnumber;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("hello-view.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 300, 200);
primaryStage.setScene(scene);
primaryStage.setTitle("Odgadnij liczbę");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
private static void setDarkMode(Stage stage, boolean darkMode) {
}
}
MainController.java
package pl.diakowski.guessingnumber.controller;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import java.util.random.RandomGenerator;
import java.util.random.RandomGeneratorFactory;
public class MainController {
@FXML
private TextField guessTextField;
@FXML
private Button guessButton;
@FXML
private Label messageLabel;
private int targetNumber;
private int attempts = 0;
@FXML
void initialize() {
// Inicjalizacja gry przy ładowaniu interfejsu
RandomGeneratorFactory<RandomGenerator> randomGeneratorFactory = RandomGeneratorFactory.getDefault();
RandomGenerator randomGenerator = randomGeneratorFactory.create();
targetNumber = randomGenerator.nextInt(1, 100);
System.out.println("Wylosowano liczbę: " + targetNumber);
guessButton.setOnMouseClicked(mouseEvent -> onGuessButtonClick());
guessTextField.setOnKeyPressed(keyEvent -> {
if (keyEvent.getCode().toString().equals("ENTER")) {
onGuessButtonClick();
}
});
}
@FXML
void onGuessButtonClick() {
try {
int guess = Integer.parseInt(guessTextField.getText());
attempts++;
if (guess == targetNumber) {
showResult("Gratulacje! Odgadłeś liczbę w " + attempts + " próbach.");
} else if (guess < targetNumber) {
messageLabel.setText("Za mało. Spróbuj jeszcze raz.");
} else {
messageLabel.setText("Za dużo. Spróbuj jeszcze raz.");
}
guessTextField.clear();
} catch (NumberFormatException ex) {
messageLabel.setText("Wprowadź poprawną liczbę.");
}
}
private void showResult(String message) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Wynik");
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
Platform.exit();
}
}
module-info.java
module pl.diakowski.guessingnumber {
requires javafx.controls;
requires javafx.fxml;
requires javafx.web;
requires org.controlsfx.controls;
requires com.dlsc.formsfx;
requires org.kordamp.bootstrapfx.core;
requires com.sun.jna;
opens pl.diakowski.guessingnumber to javafx.fxml;
opens pl.diakowski.guessingnumber.controller to javafx.fxml;
exports pl.diakowski.guessingnumber;
exports pl.diakowski.guessingnumber.controller;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>guessing-number</artifactId>
<version>1.0</version>
<name>guessing-number</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>20.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>20.0.1</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>20.0.1</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.2</version>
</dependency>
<dependency>
<groupId>com.dlsc.formsfx</groupId>
<artifactId>formsfx-core</artifactId>
<version>11.6.0</version>
<exclusions>
<exclusion>
<groupId>org.openjfx</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>20.0.1</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.7.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>20</source>
<target>20</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>guessing-number/pl.diakowski.guessingnumber.App</mainClass>
</configuration>
</plugin>
<!--<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!– Default configuration for running with: mvn clean javafx:run –>
<id>default-cli</id>
<configuration>
<mainClass>guessing-number/pl.diakowski.guessingnumber.Main</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>
我执行以下命令:
mvn compile
mvn javafx:run
运行第二个命令后,我在控制台中得到以下错误:
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: -1073740791 (Exit value: -1073740791)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
at org.openjfx.JavaFXBaseMojo.executeCommandLine (JavaFXBaseMojo.java:567)
at org.openjfx.JavaFXBaseMojo.executeCommandLine (JavaFXBaseMojo.java:434)
at org.openjfx.JavaFXRunMojo.execute (JavaFXRunMojo.java:105)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
at java.lang.reflect.Method.invoke (Method.java:578)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
org.apache.commons.exec.ExecuteException: Process exited with an error: -1073740791 (Exit value: -1073740791)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:567)
at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:434)
at org.openjfx.JavaFXRunMojo.execute(JavaFXRunMojo.java:105)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:342)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:330)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:175)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:76)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:163)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:160)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:910)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
我完全不知道这个项目出了什么问题。stacktrace中没有显示任何信息。我应该在哪里寻找解决方案?更有趣的是,当我下载HelloFX并通过IntelliJ IDEA打开时,我得到了同样的错误。
1条答案
按热度按时间ttp71kqs1#
问题似乎与Nvidia驱动程序有关:查看Intelij文档:
https://www.jetbrains.com/help/idea/javafx.html#troubleshoot
进程已完成,退出代码为-1073740791(0xC 0000409)
问题是由NVIDIA驱动程序中的错误引起的。将驱动程序更新到最新版本。有关详细信息,请参阅社区论坛