Results 1 to 3 of 3
  1. #1
    naveen516 is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Nullpointer exception

    hello,



    Java Code:
    import java.io.*;
    public class ArrayExample 
    {
    	static void add()
    	{
    		int k=9;
    		int v=8;
    		int r=k+v;
    		System.out.println(r);
    	}
    	public static void main(String args[])
    	{
    		
    		ArrayExample ar[]=new ArrayExample[5];
    		ar[0].add();
    		ar[1].add();
    		ar[2].add();
    		ar[3].add();
    		ar[4].add();
    		
    	}
    
    }
    It is giving NullpointerException, why?
    Last edited by Eranga; 12-19-2011 at 05:34 AM. Reason: code tags added

  2. #2
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: Nullpointer exception

    You are trying to access a field or method of an object which hasn't been set. From the compiler message, identify the line that is giving the exception and examine where each reference is being set. If you have any problems, post the line, with each reference and where you think you have set it.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Nullpointer Exception with BufferedWriter?
    By Solarsonic in forum New To Java
    Replies: 3
    Last Post: 03-23-2011, 01:08 AM
  2. Nullpointer Exception???
    By kipcorn91 in forum AWT / Swing
    Replies: 5
    Last Post: 10-29-2010, 12:19 AM
  3. NullPointer exception
    By bdario1 in forum New To Java
    Replies: 15
    Last Post: 03-17-2010, 05:44 AM
  4. nullpointer exception in jsp
    By fiero in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 11-07-2008, 02:44 PM
  5. NullPointer Exception
    By Preethi in forum New To Java
    Replies: 8
    Last Post: 02-06-2008, 04:40 PM

Posting Permissions

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