I am trying to make a TrieNode class. Every node has a letter, links(the other nodes it connects to), a boolean declaring if this node marks the end of a full word, and I am trying to add another boolean saying weather it is part of a valid prefix. The part I am having trouble with is the prefix part. I am trying to make an isValidPrefix method.

My TrieNode class:

```
class TrieNode
{
    char letter;
    TrieNode[] links;
    boolean fullWord;
    boolean validPrefix;

    TrieNode(char letter)
    {
        this.letter = letter;
        links = new TrieNode[26];
        for(int i=0;i<26;i++){//i keep getting a nullPointer exception
            this.links[i].validPrefix=false;
        }
        this.fullWord = false;
        this.validPrefix=true;
    }
}

```

In my add method, every time I add a node, I set that nodes `validPrefix` to true.

My is valid prefix method:

```
 public boolean isValidPrefix(TrieNode root, String word) {
    int length = word.length();
    char[] letters = word.toCharArray();
    TrieNode curNode = root;
    for (int i = 0; i < length; i++){
        curNode = curNode.links[letters[i]-97];
    }
    return curNode.validPrefix;//get a nullPointerException
}

```

Here is my add method for reference 

```
    public void insertWord(TrieNode root, String word){//97 is ascii value
    int length = word.length();
    char[] letters = word.toCharArray();
    TrieNode curNode = root;

    for (int i = 0; i < length; i++){
        if (curNode.links[letters[i]-97] == null)
            curNode.links[letters[i]-97] = new TrieNode(letters[i]);
        curNode = curNode.links[letters[i]-97];
        curNode.validPrefix=true;
    }
    curNode.fullWord = true;  
}

```