Results 1 to 4 of 4
  1. #1
    ur2cdanger is offline Member
    Join Date
    Oct 2011
    Posts
    6
    Rep Power
    0

    Default Problem with array assignment

    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.

    Java 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

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Problem with array assignment


  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: Problem with array assignment

    What variable is null?
    how to overcome this?
    To fix the problem, make sure the variable has a valid value.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,931
    Rep Power
    19

    Default Re: Problem with array assignment

    The only thing that can be null on that line is 'root'.
    As for why it is null, that is entirely down to the method 'makeleaf()', which we can't see.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. My assignment array program will not run
    By BenH in forum New To Java
    Replies: 1
    Last Post: 01-29-2012, 02:00 AM
  2. Array Programming Assignment - Digit Counter
    By ayelleeeecks in forum New To Java
    Replies: 10
    Last Post: 11-01-2011, 07:45 PM
  3. problem with assignment
    By frickenj in forum New To Java
    Replies: 9
    Last Post: 05-08-2011, 05:02 PM
  4. Very annoying error for array assignment
    By DudeJericho in forum New To Java
    Replies: 2
    Last Post: 04-20-2011, 02:07 PM
  5. The Assignment Problem
    By bumblyb33 in forum New To Java
    Replies: 5
    Last Post: 03-04-2009, 04:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •