View Full Version : Can't Get Array Working

01-25-2012, 02:07 AM
I am having great difficulty implementing an arraylist in my code. I am trying to add four values that should be in my arraylist and then return that value. I can't even try to compile my code though, as there are too many errors. Can somebody please help me, I am really lost.

import java.util.ArrayList;

public class Team {

public void T(Earnings teammate) {

ArrayList teammate = new ArrayList();



public double totalGoals() {
ArrayList Employee = new ArrayList();

double sum = 0;
for(int i = 0; i < teammate.size(); i++){

Object F = teammate.get(i);
goal E = (goal) F;

sum += team(i);


return sum;

01-25-2012, 01:47 PM
This is a problem with your scope. teammate is not available outside of the function T. You need to either return ArrayList from T and provide it as an argument for totalGoals, or you need to write it as a member for the class.
I would recommend you do not use T as a name, especially when generics could be involved. ArrayList is generic, and will generate a warning when not provided with a datatype to work with. ArrayList should be generated under the type ArrayList<String>. Since I don't know what 'goal' is, its highly probable that you cannot cast a type of String to goal.