Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Null Exception Error

    I got a Null Exception Error in my program and I have no ideas how to fix it. I posted my files in the post. The program is a text based go fish game.
    Attached Files Attached Files

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,725
    Thanks
    41
    Thanked 191 Times in 190 Posts
    Can you be a little more specific? There are a lot of files in there- What class is throwing the error? And along with that- what class calls that class?

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    jmurphy45 (03-07-2014)

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It is in the GoFish Class in line 88

    Code:
    if((P.cardsInHand[P.getnumCardsInHand()].getRank()) == rank){
                        return P;
                    }else{
                        System.out.println("Requested Players turn");
                        return (requestedPlayer);
                    }
    It happens when you ask a player for the card.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    If I *really* have to gander it without looking at the code, its the result of P.cardsInHand[P.getNumCardsInHand()] call.
    I'd presume that the cardsInHand is a pre-sized array that is greater than the number of cards currently within it. When you attempt to fetch a card from an "invalid" location (as defined by running location and not by pre-defined size location which would throw an OutOfBoundsException), it will return null which cannot be dereferenced for a method or member. If the names are logical, and you want the last card in the array based on the size, you can use P.getnumCardsInHand() - 1 instead.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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