ArrayIndexOutOfBoundException
public class Trie
{
Node root = new Node();
public void put(String k)
{
Node temp = root;
char[] chars = k.toCharArray();
if (temp.isEmpty())
{
for (int i = 0; i < chars.length; i++)
{
if (i == chars.length - 1)
temp.add(chars[i], 1);
else
{
temp.add(chars[i], 0);
temp = temp.Children[0];
}
}
}
else
{
for (int i = 0; i < chars.length; i++)
{
if (temp.Children[chars[i] - 'a'] == null)
{
if (i == chars.length - 1)
temp.add(chars[i], 1);
else
{
temp.add(chars[i], 0);
temp = temp.Children[chars[i] - 'a'];
}
}
else
{
if (temp.Children[chars[i] - 'a'].key == chars[i])
{
if (i == chars.length - 1)
temp.Children[chars[i] - 'a'].value++;
temp = temp.Children[chars[i] - 'a'];
}
else
{
if(i == chars[i])
temp.add(chars[i], 0);
temp.add(chars[i], 1);
temp = temp.Children[chars[i] - 'a'];
}
}
}
}
}
}
Sedan när jag kör får jag
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 65182
at Trie.put(Trie.java:30), varför får jag error där och hur åtgärdar jag det? Uppgiften handlar om att göra en trie och jag lägger noder för varje char