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 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









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
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
Tree Map Example
Tree Map Example     ... static void main(String[] args) { System.out.println("Tree Map Example!\n"...;(); //Addding data to a tree map tMap.put(1, "Sunday"); tMap.put(2
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
Map java Object to database.
Map java Object to database.  How do you map Java Objects with Database tables
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
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
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 code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
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
tree view - Java Beginners
tree view  I want to use tree view in my example code to display data... visit the following links: http://www.roseindia.net/java/example/java/swing/TreeComponent.shtml http://www.roseindia.net/java/example/java/swing
tree view - Java Beginners
tree view  Hello Deepak, Thanks for your help last time regarding java. I have another problem, Actually I want a tree...   Hi Friend, You are using jsp or java swing. Please clarify this. Do
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
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
tree view - Java Beginners
tree view   I m using swing for the treeview in my application and also the database(Hsqldb). I want to connect the tree view with the database fields. If u want more clarification ,let me know. Thanks
B+ tree - Java Beginners
. In this assignment, you will implement B+-tree data structure on a fixed-length data... field is separated or delimited by a white space. Initially, your B+-tree... user interface (GUI). Your GUI also visualizes B+tree structure after executing any
Java map building - Development process
Java map building  Hello All I want to build a map for a road... to proceed further i need to build a map using these coodinates which i am unable to think of how to do it. I can only use java swing or 2d for this purpose. Any
Java Map iterator with example
Java Map Iterator is an interface. It keeps the data in the key and value form. It is implemented by HashMap, Tree Map. Map has no iterator method. So...() method to get the data in Set object form. Java Map Iterator with Example
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
Map Java Objects with Database tables
Map Java Objects with Database tables  How to map Java Objects with Database tables?   First write Java domain objects ie. beans with setter and getter methods. Then map java class to table and database columns to Java
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
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
tree
tree  hi.i want search in bstree . what am i doing?   Please visit the following link: http://www.roseindia.net/tutorial/java/core/binarySearch.html
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
B+tree lodaing - Java Beginners
B+tree lodaing  hi, i have fixed-length data file such student table. All fields are fixed length: 8 for number (20022509), 3 for name (PIS), 4... or delimited by a white space. how i can Initially, constructed B+ tree based
Tree View with database - Java Beginners
Tree View with database   Hi, I'm working with Swing.I have...); JTree tree = new JTree(parent); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION
drawing a christmas tree - Java Beginners
drawing a christmas tree  how do i write a program that draws a chrimas tree using the knowledge of loops only. i.e * *** ***** ******* the program will draw a Christ mas tree  Hi ChristmasTree.javaimport java.awt.
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
Java Map Iterate
Map is an Interface in the Collection Framework. Map is implemented by its two sub classes HashMap Treemap Map has no iterator method. So use the entrySet() method.It returns the data as Set Example of Java Map
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
Using Arraylist or Hash Map - Java Interview Questions
Using Arraylist or Hash Map  what could b the pros and cons changing between Hash Map to Array List
Map interface
Map interface  What is the Map interface
google map with jsf - Java Server Faces Questions
google map with jsf  hi, i am using jsf with googlemap.i load the script file with googlemap .its working fine.how can i load the database values(latlong) to googlemap from jsf bean values.i want to show mutiple markers
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
Maven dependency for com.graphhopper - map-matching version 0.4.0-RC1 is released. Learn to use map-matching version 0.4.0-RC1 in Maven based Java projects
; com.graphhopper - map-matching version 0.4.0-RC1 in Java projects. Follow the step...; com.graphhopper - map-matching version 0.4.0-RC1 java library in your project...Maven dependency for  com.graphhopper  - Version 0.4.0-RC1 of map
Java Map Example
Java Map Example: package Collection; import java.util.HashMap; import...Map Interface adds keys to values. Every key in the Map Interface should be unique. It is part of java.util package. Each element in a map has a key
Maven dependency for org.webjars.npm - source-map version 0.7.2 is released. Learn to use source-map version 0.7.2 in Maven based Java projects
this version ( org.webjars.npm - source-map version 0.7.2 ) in their Java...Maven dependency for  org.webjars.npm  - Version 0.7.2 of source-map released The developers of   org.webjars.npm - source-map project

Ads