class Book { //// FIELDS //// private String longestWord; private int wordCount; private ArrayList<String> wordList = new ArrayList<String>(); /* Declare fields for the word list, the word count, and the longest word.*/ ////// CONSTRUCTOR ////// //@param f -- the file object public Book(File f) { wordList = readBook(f); wordCount = countWords(wordList); longestWord = findLongestWord(wordList); }
public static String findLongestWord(ArrayList<String> b) { try { String longest = b.get(0); } catch (Exception f) { System.out.println("The longest word eludes me."); } return longestWord; //Error: non-static variable longestWord cannot be referenced from a static context// }
findLongestWord
static
longestWord
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)