简体   繁体   中英

Error While creating a New Node in java

My Node Class:

static class Trie{

     int count;
     Trie[] words;

     public Trie(){
         count =-1;
            for(int i=0;i<26;i++)
            words[i] = null;
     }

}

My Line of Code For Creating a New Node:

if(Root==null)
        Root = new Trie();

I am getting the following error

Exception in thread "main" java.lang.NullPointerException

What I have Done Wrong , How to create a new object

您从未初始化过单词:

words = new Trie[26];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM