Reputation: 59
When I compile my program, I get an error saying,
cannot find symbol
symbol : variable myInput
location: class diceGame
I've looked over my code and can't seem to find the error in the read line. What does it mean? Why is this error occurring?
import java.io.*;
import java.lang.*;
import java.util.*;
public class diceGame
{
public static void main(String[] args) throws IOException {
pairOfDice dice;
dice = new pairOfDice();
playerGame player;
player = new playerGame();
int rollCount = 0;
int holdB = 0;
do {
dice.roll(); // Roll the first pair of dice.
System.out.println("Dice 1: " + dice.getDiceA() + "\n" + "Dice 2: " + dice.getDiceB() + "\n" + "The total is: " + dice.getTotal());
System.out.println("Do you want to hold the value of the dice? Press 0 to hold none/ 1 to hold die 1/ 2 to hold die 2/ 3 to hold both");
String hold = myInput.readLine();
int holdA = Integer.parseInt(hold);
if (holdA == 0){
}
if (holdA == 1){
player.getHoldA();
player.setHoldA(dice.getDiceA());
System.out.println("Value of dice A is held");
}
if (holdA == 2){
player.setHoldB(dice.getDiceB());
System.out.println("Value of dice B is held");
}
if (holdA == 3){
player.setHoldA(dice.getDiceA());
System.out.println("Value of dice A is held");
player.setHoldB(dice.getDiceB());
System.out.println("Value of dice B is held");
break;
}
rollCount++;
}
while (dice.getTurns() <= 3);
}
}
Upvotes: 0
Views: 214
Reputation: 54242
It means that on this line:
String hold = myInput.readLine();
It doesn't know what myInput
is, since you never defined it.
Most likely you want to add a BufferedReader
around System.in
, then read from that:
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String nextLine = input.readLine();
Upvotes: 2