
This is a project for a class, and I am totally stuck! I've created a tree map using an input text file. I split the lines into fields so that I could work with 2 elements from the file. It appears to display correctly, but I'm getting an "ArrayIndexOutOfBoundsException: 3" error, and I'm not getting anything returned to my Set. I just can't seem to wrap my brain around this one...can someone take a look at my code and point me in the right direction please?
[code]
public static Set<String> agentValue(String inputFileName)
throws FileNotFoundException
{
Set<String> tail = new TreeSet<String>();
SortedMap<String, Number> agentValues = new TreeMap<String, Number>();
Scanner in = new Scanner(new File(inputFileName));
String line = inputFileName;
String[] fields;
while (in.hasNextLine())
{
line = in.nextLine();
fields = line.split("\\s");
String agentId = (fields [3]);
Double pValue = Double.parseDouble(fields [2]);
if (agentValues.containsKey(agentId))
{
pValue += agentValues.get(agentId).intValue();
}
agentValues.put(agentId, pValue);
// Create keyMap with all keys and values
Set<String> keySet = agentValues.keySet();
for (String key : keySet)
{
Number value = agentValues.get(key);
System.out.println(key + " : " + value);
tail.add(key + " : " + value);
}
}
return tail;
}
[/code]
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.