Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Initialization of a class

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Initialization of a class

    I'm trying to initialize a class like this, but I get NullPointerException. What is wrong with it?


    public class TreeNode {
    private char letter;
    private TreeNode[] link;

    public void set_letter(char letter) {
    this.letter = letter;
    }

    public char get_letter() {
    return letter;
    }

    public TreeNode(char c){
    // Initialize the node
    set_letter(c);
    // Default value for links is NULL
    for(int i=0; i<10; i++){
    link[i] = null;
    }
    }

    public static void main(String[] args) throws Exception {
    TreeNode tn = new TreeNode((char)97);
    }

    }
    Last edited by Merik; October 28th, 2010 at 07:13 PM.


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    489
    Thanks
    8
    Thanked 45 Times in 43 Posts

    Default Re: Initialization of a class

    I don't see where you initialize the array.

    db

Similar Threads

  1. [SOLVED] JUnit initialization error
    By raphytaffy in forum Java IDEs
    Replies: 2
    Last Post: September 20th, 2010, 05:33 PM
  2. Initialization parameter of servlets
    By rakesh in forum Java Servlet
    Replies: 3
    Last Post: April 13th, 2010, 03:14 AM
  3. Replies: 0
    Last Post: April 11th, 2010, 08:56 AM
  4. problem with data access when a class call another class
    By ea09530 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2010, 05:20 PM
  5. Re-Initialization of FrameView app components??
    By DarkJoy in forum Java Networking
    Replies: 2
    Last Post: November 13th, 2009, 12:19 AM