I'm trying to pass an individual elements of CordsArray from the public class Enemy() to the main.
public class Enemy {
//constructor
public Enemy()
{
//*create array of coordinates
ArrayList<Integer> CordArray = new ArrayList<Integer>();
CordArray.add(0,2);
CordArray.add(1,5);
CordArray.add(2,8);
CordArray.add(3,10);
}
public static int returnCords(int[] CordArray, int index)
{
return CordArray[index];
}
I'm wanting to output elements of the CordArray to the console by calling returnCords in main:
System.out.println(returnCords(CordArray, 0));
But a 'CordArray cannot be resolved to a variable' error appears. Apologies for bad English.
CordArrayinEnemyand look at the arg list forreturnCords. You cannot pass an ArrayList when it is expecting an int array.