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

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(); ).

Cheers mate thats a lot of help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.