Results 1 to 2 of 2
  1. #1
    AxL
    AxL is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default java.lang.NullPointerException

    hi, I am creating a class and trying to create an array of that class, then giving value to the variables contained in the class but get the infamous NullPointerException. How can I give a value to the values of the variables in the class (in this case x and y)?
    Thanks

    This is my code:
    class Point {
    int x, y;
    }

    class Test {
    public static void main(String[] args) {
    Point[] pa = new Point[10];
    pa[1].x=1;
    }
    }

    This is the output:
    Exception in thread "main" java.lang.NullPointerException
    at Test.main(test.java:8)

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: java.lang.NullPointerException

    Java Code:
    String[] arr = new String[5];
    System.out.println(arr[0].charAt(0));
    What do you expect the output of that code to be?

Similar Threads

  1. PLEASE HELP ME-i got java.lang.NullPointerException
    By nandhinianand in forum NetBeans
    Replies: 4
    Last Post: 08-05-2011, 06:35 AM
  2. java.lang.NullPointerException
    By nitinverma in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-15-2010, 03:56 PM
  3. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 3
    Last Post: 02-28-2009, 05:41 AM
  4. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 1
    Last Post: 02-27-2009, 12:36 PM
  5. java.lang.NullPointerException
    By vasavi.singh in forum New To Java
    Replies: 2
    Last Post: 02-27-2009, 10:11 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
  •