I am working on a school project and I am having trouble with taking information from a text file, putting it into a treeset then converting it to a treemap.
/* * This application reads listing file, stores the property type data * into a set, returns a map */ package gtt1t2a; import java.util.*; import java.io.*; /** * * @author Monica l */ public class t2a { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { //prompt user for filename Scanner in1 = new Scanner(System.in); System.out.print("Enter the File Name[listings.txt]: "); String in1FileName = in1.nextLine(); //Scanner objects for the class File in1File = new File(in1FileName); Scanner in2 = new Scanner(in1File); //create new hash set Set<String> propertyListings = new TreeSet<String>(); //get the data from the listings file while (in2.hasNext()) { String propType = in2.nextLine(); propertyListings.add(propType.toUpperCase()); //add treeset collection to map Iterator<String> iter = propertyListings.iterator(); Map<String, Integer> agentListings = new TreeMap<String, Integer>(); while (iter.hasNext()) { String propNum = iter.next(); agentListings.put(propNum, new Integer(01)); String property = iter.next(); agentListings.put(property, Integer.getInteger(property)); String propPrice = iter.next(); agentListings.put(propPrice, Integer.getInteger(propPrice)); String agentNum = iter.next(); agentListings.put(agentNum, Integer.getInteger(agentNum)); Set<String> keySet = agentListings.keySet(); for (String key : agentListings.keySet()) { Integer value = agentListings.get(key); System.out.println(value); } } } in1.close(); in2.close(); } }
The error I get is:
[ERROR] Exception in thread "main" java.util.NoSuchElementException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(T reeMap.java:1098)
at java.util.TreeMap$KeyIterator.next(TreeMap.java:11 54)
at gtt1t2a.t2a.main(t2a.java:47)
Java Result: 1
BUILD SUCCESSFUL (total time: 9 seconds)[/ERROR]
Any help is appriciated