我收到IllegalArgumentException错误:尝试显示骰子图像时出现无效的URL错误。错误发生在playRound方法中,该行由注释标记。当用户点击掷骰子按钮时,会出现此错误,掷骰子按钮将显示用户掷骰子。我的图像位于项目的“我的图像”文件夹中。任何帮助将不胜感激,谢谢。
Netbeans项目结构
我已经打印出文件是否存在,以查看我的网址是否正确。它表明该路径存在,但是我仍然收到无效的URL错误。
private static void playRound() {
playerIndex = 0;
maxScore = 0;
hitButton.setDisable(false);
standButton.setDisable(false);
blackJackRoundPlayer = blackJackRound.get(playerIndex);
playerName.setText("Player Name: " + blackJackRoundPlayer.getPlayer().getPlayer());
currentBalance.setText("Player Holdings: " + Integer.toString(blackJackRoundPlayer.getPlayer().getCurrentHoldings()));
betAmountLbl.setText("Wager Amount: " + blackJackRoundPlayer.getRoundWager());
currentBalance.setText("Current Holdings: " + blackJackRoundPlayer.getPlayer().getCurrentHoldings());
hitButton.setOnAction(e -> {
roll1 = rollDice();
roll2 = rollDice();
//validate file exists
System.out.println("Dice Roll 1: " + new File(".\\src\\blackjack\\Images\\dice-six-faces-" + roll1 + ".png").exists());
System.out.println("Dice Roll 2: " + new File(".\\src\\blackjack\\Images\\dice-six-faces-" + roll2 + ".png").exists());
System.out.println("dice-six-faces-" + roll1 + ".png");
dice1View.setImage(new Image(".\\src\\blackjack\\Images\\dice-six-faces-dice-six-faces-" + roll1 + ".png"));/*error occurs on this line*/
dice2View.setImage(new Image(".\\src\\blackjack\\Images\\dice-six-faces-dice-six-faces-" + roll2 + ".png"));
blackJackRoundPlayer.addToRoundScore(roll1 + roll2);
roundScore.setText("Round Score: " + blackJackRoundPlayer.getRoundScore());
//player score is 21 or break
if (blackJackRoundPlayer.getRoundScore() >= 21 && playerIndex <= blackJackRound.size()) {
playerIndex++;
if (playerIndex <= players.size() - 1) {
if (blackJackRoundPlayer.getRoundScore() > maxScore) {
maxScore = blackJackRoundPlayer.getRoundScore();
}
blackJackRoundPlayer = blackJackRound.get(playerIndex);
playerName.setText("Player Name: " + blackJackRoundPlayer.getPlayer().getPlayer());
currentBalance.setText("Player Holdings: " + Integer.toString(blackJackRoundPlayer.getPlayer().getCurrentHoldings()));
betAmountLbl.setText("Wager Amount: " + blackJackRoundPlayer.getRoundWager());
currentBalance.setText("Current Holdings: " + blackJackRoundPlayer.getPlayer().getCurrentHoldings());
roundScore.setText("Round Score: " + blackJackRoundPlayer.getRoundScore());
} else {
hitButton.setDisable(true);
standButton.setDisable(true);
determineWinner(maxScore);
}
}
});
standButton.setOnAction(e -> {
playerIndex++;
if (blackJackRoundPlayer.getRoundScore() > maxScore) {
maxScore = blackJackRoundPlayer.getRoundScore();
}
if (playerIndex <= players.size() - 1) {
blackJackRoundPlayer = blackJackRound.get(playerIndex);
playerName.setText("Player Name: " + blackJackRoundPlayer.getPlayer().getPlayer());
currentBalance.setText("Player Holdings: " + Integer.toString(blackJackRoundPlayer.getPlayer().getCurrentHoldings()));
betAmountLbl.setText("Wager Amount: " + blackJackRoundPlayer.getRoundWager());
currentBalance.setText("Current Holdings: " + blackJackRoundPlayer.getPlayer().getCurrentHoldings());
roundScore.setText("Round Score: " + blackJackRoundPlayer.getRoundScore());
//determine winner
} else {
hitButton.setDisable(true);
standButton.setDisable(true);
determineWinner(maxScore);
}
});
}
Dice Roll 1: true
Dice Roll 2: true
dice-six-faces-4.png
Exception in thread "JavaFX Application Thread"
java.lang.IllegalArgumentException: Invalid URL: Invalid URL or