c# - Object reference not set to an instance of an object - Black Jack Game -
I'm a bit of a programming novice and I'm making a black jack game, but I'm really struggling when I get this message from the object. I know that the solution really is really clear, but can you please help? The problem is below / * main square * / / * Card class * / / * hand class * / / * Deck orbit * / An exception has been thrown where debugging through function should clearly show such issues - you can see the variables used and see which values are expected and who do not hit function, then add one card to the player's hand with my fired deck,
hit () function
Using the system; Using System.Collections.Generic; Using System.Text; Namespace BlackJackGameX {public class main class {public static zero main (string [] arg) {deck card = new deck (); Hand player hand = new hand (card); Console WrightLine ("Welcome to Black Jack \ n \ nPress Enter to get started"); Console Readline (); Cards.Hit (); PlayerHand.PrintHand (); }}}
using the system; Using System.Collections.Generic; Using System.Text; Namespace Black Jack GameX {Public Swan, Hearts, Clubs, Diamonds} Public Face (Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King) Public Face Card {public suit card suit; Public face value card value; Public IT iValue; Public Cards (Suits CardSuite, Face Value Card Value, Int ivalue) {CardSuit = cardSuit; Card Values = Cardgulls; IV = ivalue; } Public card () {}}}
using System.Collections.Generic; Using System.Text; Named Location Black Jack Game {Public Class Hand {Public List & lt; Cards & gt; PlayerHand; Private deck carded deck = new deck (); Public hand (deck card) {cardDeck = card; } Public Zero printhand (for ((int i = 0; i.m. player player; ++ i) {console. [I] .cardSuit;; (i & lt; PlayerHand.Count) {Console.WriteLine ("& amp;");}} console .readline ();}}}
using
public list & lt; Cards & gt; PlayerHand; is never assigned to its
hand class and always
null . In
hits you call
playerHand.PlayerHand is
null < / Code>, therefore code
add result in
NullReferenceException .
Comments
Post a Comment