Java: Cannot find symbol - variable faceValue

Sean :

I am making a program that prints the color of the cube and the number of sides it has, and then rolls the dice 10 times to print the numbers. I am having a problem with for loop that is supposed to roll the dice. When I compile, it has an error saying that it cannot find symbol - variable faceValue. I defined faceValue but it still says it cannot find the symbol. This is my runner code.

public class ProbilityCubeRunner
{
    private String faceValue;
    public static void main ( String[] args )
    {
       ProbilityCube cube1 = new ProbilityCube ("yellow", 10);
       System.out.println(cube1);
       int sides1 = cube1.sides;

       for(int i = 0; i < 10; i++)
       {
        int x = 1+(int)(Math.random()*sides1);
         if(i<9)
        {
           faceValue = faceValue + x + ",";
        }
         else
        {
           faceValue = faceValue + x;
        }
       }
       System.out.println(faceValue);

       System.out.println();
    }
}

How do I define the symbol string variable faceValue?

Subramanian Mariappan :

Your faceValue should be static. You cannot access non-static variables from a static method. Since your main method is a static one. The variable faceValue you are accessing from it should also be static.

Change the declaration if faveValue as follows.

private static String faceValue;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=23228&siteId=1