Why Does my entries not work with .hasNext()?
Im doing this code with HeapSort and i want to make it read a txt file count and order alphabetical all the words, but i get an error on the while(entry.hasNext()) that i cant solve, anyone knows why this happens?? public static void main(String[] args) throws FileNotFoundException, IOException { String cami="C:\\Users\\Carlos\\Documents\\NetBeansProjects\\Practica3_Text\\src\\"; FileReader fr = new FileReader(cami+"TM.txt"); BufferedReader br = new BufferedReader(fr); int n; int mida=0; String s = br.readLine(); // reads a single line Map<String,Integer> Map = new HashMap<String, Integer>(); while(s!=null) { String[] t=s.split("\\s"); // split by spaces and generates an array of Strings -words- for(int i=0;i<t.length;i++){ Iterator<Map.Entry<String, Integer>> entries = Map.entrySet().iterator(); if(Map.containsKey(t[i])){ for(Map.Entry<String, Integer> entry : Map.entrySet()){ System.out.println("Clave: "+ entry.getKey()+"Valor: "+entry.getValue()); if(t[i].equals(entry.getKey())){ Map.put(entry.getKey(),entry.getValue()+1); }} }else{ Map.put(t[i],1); } } s = br.readLine(); } HeapSort<String> hs = new HeapSort<>(mida); br.close(); while(entry.hasNext()){ Map.Entry<String, Integer> entry = entry.next(); hs.Insert(entry.getKey()); //System.out.println("clave=" + hs.Lesser() + ", valor=" + Map.get(hs.Lesser())); } while(!hs.Empty()){