Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java tree map trouble

Have Programming Question? Ask it here!
 
 
 


Lorna Robinson
Java tree map trouble
0 Answer(s)      3 years and 5 months ago
Posted in : Java Beginners


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]

Advertisement
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
TreeMapExample.java C:\vinod\collection>java TreeMapExample Tree Map... Tree Map Example     ...(String[] args) { System.out.println("Tree Map Example!\n"); TreeMap <
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
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
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
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
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 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 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
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
Tree
Tree  print("code sample");1) Write Java code to create the following tree using new Tree state- ments: 1
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
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
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
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
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
java code to compare two hash map objects
java code to compare two hash map objects  java code to compare two hash map objects
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
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 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
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
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.
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
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
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
Reversing all root-to-leaf paths in a tree (JAVA) - Java Beginners
Reversing all root-to-leaf paths in a tree (JAVA)  A root-to-leaf path in a tree is defined to be a sequence of nodes starting from the root node and proceeding downwards to a leaf. Required that given a tree, output the tree
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
Java Map Example
the key and values. Map.Entry defines both of these methods. Java Map Example...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
B+ tree JAVA source code for implementing Insertion and Deletion - Java Beginners
B+ tree JAVA source code for implementing Insertion and Deletion  Can anyone plz mail de B+ tree JAVA source code for implementing Insertion...().Start()); } } class BTreeDemo { public int Start(){ Tree
binary tree
://www.roseindia.net/java/java-get-example/java-binary-tree-code.shtml http://www.roseindia.net/java/java-get-example/java-binary-tree-insert.shtml...binary tree  can a binary tree be implemented with out comparing
Balance multi-way tree implimentation reating database - Java Beginners
Balance multi-way tree implimentation reating database  I am doning a project in which I have to create a database product in java where user can... database like Access,MySQL.As we know database is based on Balance multi-way tree
Java binary tree code
Java binary tree code     ... especially in mathematics and Boolean. The java binary tree find its application... in understanding Java binary tree code. For this we have a class name BinayTreeExample.Inside
Map interface
Map interface  What is the Map interface
Creating Database using B+Tree in Java - Java Beginners
Creating Database using B+Tree in Java  I'm doing a project in which I have to create an Object Oriented Database using B+Tree in Java... Node(25); System.out.println("Building tree with root value
Generate area for map from backing bean - Java Server Faces Questions
Generate area for map from backing bean  I need to populate the map in my page, and the coordinates should come from the backing bean.. How could I do
java run time textfield and use with map - Java Beginners
java run time textfield and use with map  i want to program which read data from file and store in map and display in different textfields which are generated at run time like a text file store information class a1
 

 

 

DMCA.com