Java tree map trouble

Ads
 

Java tree map trouble

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]
View Answers

Ads









Related Tutorials/Questions & Answers:
Java tree map trouble
Java tree map trouble  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
Trouble in running Dos Command from Java Servlet
Trouble in running Dos Command from Java Servlet  Hello All, I have to run following command from Java. The command is : vscanwin32 /S C:\Test > C... 'cmd /c dir /s'. Looking forward for the help. -Java Beginner
Advertisements
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three condition such as x<5,5<=x<10 and 10<=x<15 after that we have
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
tree in java
tree in java  Can you help me to draw the tree? First we assign the parent node. when child node(x) come we must check the condition. there are three... average of children. Like following tree. (3+7+12)/3=7(root
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
Building a Binary Tree using std::map, std:set
Building a Binary Tree using std::map, std:set  Hi, can someone please explain to me how I can make use of std::map and/or std::set to create... to represent a binary tree because I can't help but to see that map and set act
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
Java Map Example
Java Map Example  How we can use Map in java collection?   The Map interface maps unique keys to value means it associate value to unique...(String[] args) { Map mp = new HashMap(); mp.put(new Integer(2
java tree expressions - XML
java tree expressions  hi all, i have a problem in tree expressions. see there is a document tree like a parent document has no. of child... code to solve the problem and visit to : http://www.roseindia.net/java
Java Map
Java Map         In Java, a Map is a kind of generalized array. It provides a more general way of storing elements. It is an object that maps keys to values. Map
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
How to convert map to json in Java
How to convert map to json in Java  Hi, I my program I have an object of HashMap and I have to output this into json string. How to convert map to json in Java? Thanks   Hi, You have to use the Google Gson library
How to convert map to json in Java
How to convert map to json in Java  Hi, I my program I have an object of HashMap and I have to output this into json string. How to convert map to json in Java? Thanks   Hi, You have to use the Google Gson library
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
Map
Map  If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going through the map either iterator or for each loop or for loop
ModuleNotFoundError: No module named 'trouble'
ModuleNotFoundError: No module named 'trouble'  Hi, My Python... 'trouble' How to remove the ModuleNotFoundError: No module named 'trouble... to install padas library. You can install trouble python with following command
How do you map Java Objects with Database tables?
How do you map Java Objects with Database tables?  Hi, How do you map Java Objects with Database tables? thanks
map
map  using map, i want display message based on id selected [both are strings]   i do no   Hi Friend, Try the following code...) { Map map=new HashMap(); map.put("Message1","Hello
how to iterate a map in java using for each
how to iterate a map in java using for each  Hi, I have a HashMap in Java and there is need to iterate all the items. how to iterate a map in java... of Java 8: import java.util.HashMap; import java.util.Map; public class MapIterate
how to iterate a map in java using for each
how to iterate a map in java using for each  Hi, I have a HashMap in Java and there is need to iterate all the items. how to iterate a map in java... of Java 8: import java.util.HashMap; import java.util.Map; public class MapIterate
how to iterate a map in java using for each
how to iterate a map in java using for each  Hi, I have a HashMap in Java and there is need to iterate all the items. how to iterate a map in java... of Java 8: import java.util.HashMap; import java.util.Map; public class MapIterate
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Trouble with array manipulation
Trouble with array manipulation  For this project I have to print 10 random numbers from (0-99), print the max value, the average of the ten numbers... 16 14 68 80 23 This is the code i attempted, but i am having trouble putting

Ads