0

Hi there

First off I don't want you guys to tell me the answer that way I learn nothing., but if you could give me a pointer to what I am doing wrong it would help alot cheers :D

What I am trying to do is get a dice to roll 5 times and store it in an array. I am having problems with the while loop.

public void rollBoard () 
  {
      dieNum=0;
      while (dieBoard[dieNum] <= dieBoard.length){
           Die.roll();
           dieNum++;
           
           }
                 
  }

and heres Die.roll

public void roll () 
  {
       die = (int) Math.floor(Math.random()*6+1);
       
  }

When I try to compile it says Non-Static method cannot be referanced from a Static context.

Any pointers would be greatly appreciated thanks

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by SpaceDog
0

If you want to call roll() by referencing the Class (i.e. Classname.methodName() ), then roll() needs to be static. If it is not static, then you need to instatiate an instance of the class in order to able to call the method (i.e. Classname a = new Classname(); a.methodName(); or even for a one-offer (new Classname()).methodName(); ).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.