at the moment I am just doing some practise in java:
Main:
import java.util.ArrayList;
import java.util.Random;
import javax.swing.JOptionPane;
import settelersofcatan.playerinformation;
public class settlersofcatanhelper
{
private ArrayList<playerinformation> PlayerArray = new ArrayList<playerinformation>();
public static void main(String[] args)
{
String NumberOfPlayersString = JOptionPane.showInputDialog("How many player");
int NumberOfPlayers = Integer.parseInt(NumberOfPlayersString);
for (int Counter = 0; Counter < NumberOfPlayers; Counter++)
{
String Name = JOptionPane.showInputDialog("Name of player " + Counter);
String Colour = JOptionPane.showInputDialog("which colour are you playing with");
playerinformation PlayerDetails = new playerinformation(Name, Colour, Counter);
addplayer(PlayerDetails);
}
}
public void addplayer(playerinformation player)
{
this.PlayerArray.add(player);
}
}
Helper Class:
package settelersofcatan;
public class playerinformation {
String PlayerName;
String Colour;
int Position;
public playerinformation(String name, String colour, int position)
{
setPlayerName(name);
setColour(colour);
setPosition(position);
}
public String getPlayerName() {
return PlayerName;
}
public void setPlayerName(String playerName) {
PlayerName = playerName;
}
public String getColour() {
return Colour;
}
public void setColour(String colour) {
Colour = colour;
}
public int getPosition() {
return Position;
}
public void setPosition(int position) {
Position = position;
}
}
The Problem that I am having now is that I am trying to add a player's information and get the response "Cannot make a static reference to the non-static method addplayer(playerinformation) from the type settlersofcatanhelper". I have looked over the code where I have this working but cant see any difference or reason why it wouldnt work. Can anyone help me?