Results 1 to 3 of 3
  1. #1
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    160
    Rep Power
    5

    Default why this pgm is getting NUllPointer.

    hi
    why this pgm is getting NUllPointer.
    XML Code:
    public class Split {
    	static Integer intobj;
    	static void print(int val){
    		int x=10;
    		System.out.printf("%d", x+val);
    	}
    public static void main(String[] args) {
    	print(intobj);
    }
    }

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: why this pgm is getting NUllPointer.

    You need to initialize intobj.
    use:

    static Integer intobj = new Integer(10);

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default Re: why this pgm is getting NUllPointer.

    Or, declare intobj as an int.
    The difference being Integer is an object whilst int is a primative data type.

    Regards.

Similar Threads

  1. nullpointer exception
    By empire in forum Eclipse
    Replies: 3
    Last Post: 06-12-2013, 03:31 AM
  2. NULLPointer Exception
    By phyzix5761 in forum New To Java
    Replies: 7
    Last Post: 11-08-2012, 04:53 AM
  3. Nullpointer exception
    By Games2Design in forum New To Java
    Replies: 4
    Last Post: 10-20-2012, 12:15 AM
  4. Nullpointer exception
    By naveen516 in forum New To Java
    Replies: 2
    Last Post: 12-19-2011, 04:36 AM
  5. NullPointer help
    By moosick in forum AWT / Swing
    Replies: 1
    Last Post: 04-02-2011, 02:35 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
  •