Sorry if I am asking this question that has been already asked, but I am kind of a noob at programming, I tried researching how to fix this bug but I am still having trouble trying to solve it. I am trying to compile this block of code here:
//Default constructor
public Game () {
potAmount = 100;
betAmount = 0;
}
public int getBetFromUser() {
//Introduction to the game
System.out.println("Welcome to Solitaire Dice Game..bet an amount\r\n" +
"\t-if you roll triples you win triple your bet,\r\n" +
"\t-if you roll doubles you win double your bet,\r\n" +
"\t-if you roll 10 or over, you keep your bet\r\n" +
"\t-otherwise you lose your bet\r\n" +
"A bet of 0 ends the game\r\n");
System.out.println("Your current pot is 100");
System.out.println("Enter your bet amount:");
betAmount = keyboard.nextInt();
return betAmount;
And I am trying to call it in my main class but I get this compile error:
Enter your bet amount:
Exception in thread "main" java.lang.NullPointerException at Game.getBetFromUser(Game.java:26) at Assign3.main(Assign3.java:9)