Basically I have two snippets of code. One calls a function that populates and returns an ArrayList
, but I am having some issues. Here are the two codes:
Defining the receiving
ArrayList
, then catching the returningArrayList
.ArrayList agentArray = new ArrayList<>(); agentArray = agentListings(strInput);
Building the ArrayList then returning it.
public static ArrayList agentListings(String strInput) throws FileNotFoundException { File inputFile = new File(strInput); Scanner in = new Scanner(inputFile); ArrayList<String> agentArray = new ArrayList<>(); while (in.hasNextLine()) { agentArray.add(in.next()); in.next(); in.next(); in.next(); } Collections.sort(agentArray); in.close(); return agentArray; }
Problem is when I get back to where I am trying to put it into an ArrayList
once returned, it seems to work fine. But when I try and write it to a file, it throws this error from this code.
out.write(agentArray.get(1));
I am writing to a file with out being a bufferedwriter which works with simple text and such.
Basically I can't figure out how to write the ArrayList "agentArray" to the file. Any obvious errors am I doing?
==============================================
EDIT:
Forgot to include the error. When i hover over the out.write(agentArray.get(1));
the agentArray
gets underlined in red and the error is
cannot find symbol symbol: varible agentArray
location: class blabla.blabla