I am trying to get a list of the longest words from each line in a block of text. I cant get the information to print from my main which is in processing.class. The information is processed in Tools.class. and there is also a Counters.class that is involved but it is immutable.
However, it gives me this warning: The value of the local variable longestWords is not used
in my counter code, on the line where i declare longestWords =h;
. Why is this, and how can I fix it?
This is my code:
(Processing)
longestWords = stat.getLongestWords();
for(i = 0; i < longestWords.size(); i++){
System.out.print(longestWords.get(i));
}
Error thrown: Exception in thread "main" java.lang.NullPointerException at deol5210_a1.Processing.main(Processing.java:66)
which points to for(i = 0; i < longestWords.size(); i++){ (Tools)
}else {
currentWord = lineScanner.next();
if(currentWord.contains("$")){
currentWord.replace("$", "");
moneySpent += Double.parseDouble(currentWord.replace("$", ""));
}else if (currentWord.length() > lineLongestWord.length()){
lineLongestWord = currentWord;
}
if(currentWord.length() > longestWord.length()){
longestWord = currentWord;
lineLongestWord = currentWord;
wordCount++;
} else {
wordCount++;
}
(Counters)
public ArrayList<String> getLongestWords(){
return longestWords;
}
public Counters(int a, double b, int c, int d, double e, double f, String g, ArrayList<String> h){
lineCount = a;
avgWordCount = b;
wordCount = c;
purchaseCount = d;
moneySpent = e;
avgSpent = f;
longestWord = g;
ArrayList<String> longestWords = h;
}