Problem with array initialization
I have been working in creating a B+ tree. I have certain problem in code. Please tell me what are the errors and how can I overcome it? I am giving the snippet where the error occurs.
Code :
class record
{
public int value;
}
class node
{
Object[] pointers ;
int[] keys;
node parent;
boolean is_leaf;
int num_keys;
node next;
record r;
}
node start_new_tree(int key, record pointer)
{
System.out.println(key+pointer.value);
node root = d.makeleaf();
root.keys[0]=key; // The error is here.It gives null pointer exception
root.pointers[0] = (Object)pointer;
root.pointers[order - 1] = null;
root.parent = null;
root.num_keys++;
//System.out.println(root.keys[0]+" "+root.pointers[0]+" "+root.num_keys);
return root;
}
When I use start_new_tree in my main,this gives nullpointer exception at the place mentioned.Can you tell me how to overcome this?
Thank you
Re: Problem with array initialization
Re: Problem with array initialization
Does method called makeleaf() initialize arrays of node class?
For example:
Code JAVA:
public node makeleaf(){
node newnode = new node();
...
newnode.num_keys = 5;
// this line is important otherwise keys is null and throws NullPointerException
newnode.keys = new int[newnode.num_keys];
...
return newnode;
}