2
Good afternoon!
I am making a hash table and for this I am trying to create an AVL tree vector. The problem is that when I try to insert a value in any tree of this vector is giving the exception "Nullpointerexception". Could someone tell me where I’m going wrong?
I am very grateful.
public class Hashing {
ArvoreAvl[] lAVL;
int mod;
public Hashing(int tamanho){
lAVL = new ArvoreAvl[tamanho];
mod = tamanho;
}
public void inserir(int valor){
int rest = valor % mod;
for(int x = 1; x < lAVL.length; x++){
if(x == rest){
// Está dando java.lang.NullPointerException na linha abaixo
lAVL[x].inserir(valor);
}
}
}
public void remover(int valor){
int rest = valor % mod;
for(int x = 0; x < mod; x++){
if(x == rest){
lAVL[x].remover(valor);
}
}
}
public void imprimir(){
for(int x = 0; x < lAVL.length; x++){
lAVL[x].inorder();
System.out.println();
}
}
But I’m doing it in the class builder.
– Gustavo Cruz
No no, in the class constructor you are not instantiating hehe you have to instantiate each node of your vector, I will edit the answer if you can understand better.
– Dev
Ahh, now I understand Matheus. Thank you very much for your help. :)
– Gustavo Cruz