Help needed .. Null pointer Exception..
[B][I][U]//Execution class ....... [/U][/I][/B] public class Execution { /** * @param args */ public static void main(String[] args) { WordList wordList = new WordList(); Word word1 = new Word("abd"); Word word2 = new Word("abdede"); Word word3 = new Word("abddwd"); // TODO Auto-generated method stub wordList.addWord(word1); //NUll Point Exception here.. Can some one explains why??? wordList.addWord(word2); wordList.addWord(word3); wordList.displayWordsOfLength(2); } } [B][I][U]//////WordList Class[/U][/I][/B] import java.util.ArrayList; public class WordList { ArrayList<Word> wordList; public WordList() { super(); } public ArrayList<Word> getWordList() { return wordList; } public void setWordList(ArrayList<Word> wordList) { this.wordList = wordList; } public void addWord(Word word) // NULL POINTER EXCEPTION PLEASE EXPLAIN WHY? { wordList.add(word); } public void displayWordsOfLength(int length) { for(Word word :wordList) { if(word.getWord().length()== length) System.out.println("Word with length: "+length+" "+word.getWord()); } } public void removeWord(String inputWord){ for(Word word :wordList) { if(word.getWord().equalsIgnoreCase(inputWord)) { wordList.remove(word); System.out.println("Word "+inputWord+" is removed "+word.getWord()); } } [I][U][B]//WORD CLASS[/B][/U][/I] public class Word { private String word ; private int length ; public Word(String word) { super(); this.word = word; } public String getWord() { return word; } public void setWord(String word) { this.word = word; } }