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 9 of 9

Thread: error in my code(Exception in thread "main" java.lang.NullPointerException)

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default error in my code(Exception in thread "main" java.lang.NullPointerException)

    hey guys i am getting frustrated about this work,i am getting error like this
    Exception in thread "main" java.lang.NullPointerException
    at Game.<init>(Game.java:21)
    at Bullclia.main(Bullclia.java:6)


    any reason why i am getting this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    Exception in thread "main" java.lang.NullPointerException
    at Game.<init>(Game.java:21)
    There is a variable with a null value on line 21. Look at line 21 in the your source and see what variable is null. Then backtrack in the code to see why that variable does not have a valid value.
    If you can not tell which variable it is, add a println just before line 21 and print out the values of all the variables on that line.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    i have assigemenet to do if you can help me with,
    i have an class called Choice and it has constructor which takes array and store it in his array(attribute in Choice class)

    ,i have an game class which need to have an array of 5040 cells of Choice,and i need to store it with numbers from 1 to 9999 with deference digits(Which combines all to 5040 numbers)
    i am getting stucked at this
    at first i do
    1. Choice [] carray;
    2. and i do a loop of 9999 times to check with if's for the numbers i need when i find number like 0123,i store it in array(xarr)
    3. carray[0]=new Choice(xarr);


    i am getting error at line 3 its not working for :S

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    i am getting error at line 3
    Please copy the full text of the error message and post it here.

    BTW an array with 5040 slots can not hold 9999 values. It can only hold one value per slot: 5040 max
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    Post the code and the full text of the error message with your question

  6. #6
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    i figured out my problems but i donot know how to solve it like i explained here i have to do
    i have class called Choice ,it has constructor which takes array and store it in his array attribute!
    i have game class,which consists an array of 5040 cells of Choice objects,and i need to store in this array number with deference digits,i got 9999 numbers which only 5040 number has different digits in it,like 0123,4567,3451 and etc..


    i need to know how to write the array of 5040 in game attribute and how do i store numbers in his array cells lke(0123) ?

    seems if i put
    Choice[] arr=new Choice[5040]; i am getting an error how do i do it?

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    i am getting an error
    Please copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Apr 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    its k i solved it

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: error in my code(Exception in thread "main" java.lang.NullPointerException)

    Please mark this thread as solved. See Thread tools at top
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: April 7th, 2013, 03:40 PM
  2. Replies: 1
    Last Post: February 27th, 2013, 06:48 AM
  3. Replies: 3
    Last Post: December 7th, 2011, 02:03 AM
  4. [SOLVED] Error Message: Exception in thread "main" java.lang.NullPointerException etc.
    By coffecupcake in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 15th, 2011, 09:34 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM