For an assignment I've come across an Issue. For a bit of a boost I'll tell you what it is I'm working on.
The assignment requires me to create a java applet (Even though I'm using a JFrame, oops) that gets input from the user in the form of a piece of text. With this text, the program will how many of each length of word there are and display the results in the form of a graph in a separate window. My hashmap contains two Integers, the length of the word and how many of that length there is.
However the assignment requires that the user be able to upload two text files and compare the results, therefore I have to send an array of hashmaps, each with separate results to the window. I have been doing that this way:
public void dispatchNewGraph (ArrayList<Map<Integer, Integer>> sortedCount) {
TextAnalyserGraph graphFrame = new TextAnalyserGraph(sortedCount);
}
and in the window that opens, the data passed to the constructor is applied to this property in the TextAnalyserGraph class private ArrayList<Map<Integer, Integer>> graphData;
My issue is that I'm getting a nullpointerexception error when I try to iterate this Array of HashMaps with the following code:
for(Iterator<Map<Integer, Integer>> i = graphData.iterator(); i.hasNext(); ) {
Map<Integer, Integer> graph = i.next();
for (Integer value : graph.keySet()) {
if(graph.containsKey(value)) {
Integer v = graph.get(value);
if (v.intValue() > largest)
largest = v.intValue();
}
bars++;
}
}
The error starts at the first line of that last code block. If I move graphData to the next line, the same error starts point there indicting an issue with graphData., I'm really struggling to make progress on this!
Thanks very much! :)
Stacktrace
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at TextAnalyserGraph.paint(TextAnalyserGraph.java:47)
at javax.swing.RepaintManager$3.run(RepaintManager.java:819)
at javax.swing.RepaintManager$3.run(RepaintManager.java:796)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:796)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:769)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:718)
at javax.swing.RepaintManager.access$1100(RepaintManager.java:62)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1677)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
However the assignment requires that the user be able to upload two text files and compare the results, therefore I have to send an array of hashmaps, each with separate results to the window.If you know there is only 2 Maps, why do you need an array? Why not use a Pair, or pass the 2 maps as separate arguments.The error starts at the first line of that last code block, which would befor(Iterator<Map<Integer, Integer...