我是一名新程序员,刚刚开始使用Eclipse.以前,我使用JGRASP,当我想要一个按钮添加图像时,我所做的就是Image在类的文件夹中创建一个文件夹并写入:
setIcon(newImageIcon(this.getClass().getResource("/Images/name.png")));
我用Eclipse尝试了同样的事情,但是我收到了一个main:NullPointerException错误.
我已经阅读了另一篇文章并source folder在我的项目中添加了一个名为Images但没有改变的项 以下是我遇到问题的代码段:
resetButton.setIcon(newImageIcon(this.getClass().getResource("/Images/helpIcon.png")));
我编写了一个二十一点,我希望play()每次玩家输掉时执行该方法.如:
public void play()
{
System.out.println("Your balance: $" + playerBalance + "\nHow much would you like to bet?");
playerBet = keyboard.nextInt();
System.out.println("Your bet: $" + playerBet);
if(playerTotalValue > 21)
{
playerBalance -= playerBet;
System.out.println("You are busted.\nYour balance: $" + playerBalance);
System.out.println("Press enter to continue...");
keyboard.next();
play();
}
else if(dealerTotalValue > 21)
{
playerBalance += playerBet;
System.out.println("The house is busted.\nYour balance: $" + playerBalance);
System.out.println("Press enter to continue...");
keyboard.next();
play();
}
Run Code Online (Sandbox Code Playgroud)
这当然不能像我想要的那样工作!任何帮助,将不胜感激.
我试图删除arraylist中的所有元素,deck但由于某种原因deck.size()应该是52返回26并且只删除了26个元素.
public void remove()
{
int k = 0;
while(k < deck.size())
{
deck.remove(0);
k++;
}
}
Run Code Online (Sandbox Code Playgroud)
我打电话给numberOfCards()在main返回deck.size(),并返回52,所以我不知道为什么deck.size()在只取出返回26.