I am developing an android board game and I am stuck with an error from one of my parameters. It is a mancala-based game with a view (TableView.class) containing rows of pits with stones in then, and a main activity (Game.class). I am attempting to define a pit and its contents.
Here is a snippet of the code:
public class Game extends Activity {
int pitIndex, pitContents;
int _pitContents=4;
int pitsPerRow=5;
//more code here .......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
table_view = getInitialTableView();
tableView = new TableView(this);
setContentView(tableView);
tableView.requestFocus();
//...more code here
//
// ...
// define a playing pit
public int Pit(int pitIndex, int pitContents) {
this.pitIndex=pitIndex;
this.pitContents=pitContents;
}
// set player1's pits and populate them
public int Player1Pits[] = new int[16*2];
{
for (int i = 0; i < (2 * pitsPerRow); i++) {
if (i < pitsPerRow) {
Player1Pits[i] = new Pit(i,_pitContents);
else {
// do nothing
}
}
}
//.....
}
The error I get from Eclipse is that “Pit cannot be resolved to a type” when I try to instantiate a new pit:
Player1Pits[i] = new Pit(i,_pitContents);
Does anyone know where I am going wrong? Do I have to define Pit as a class outside the Game class?
I have searched exhaustively for a solution before posting this question. Your input will be appreciated. Thanks in advance.
Get rid of your method called Pit and make a pit class like this:
What languages are you familiar with by the way?