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

    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)
    		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;
    		//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
    Rep Power

    Default Re: Problem with array assignment

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    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
    Rep Power

    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