c# - Object reference not set to an instance of an object -


public player(string name, list<card> cards) {    this.name = name;    try    {       this.stack.insertcards(cards);//here nullreferenceexeption    }    catch (exception e)    {                       throw e;    } }  public void insertcards(list<card> cards) {    stack.addrange(cards); }  public list<card> getsevencards() //the player gets cards function {    list<card> list = new list<card>();    int ran;    random r = new random();    (int = 0; < 7; i++)    {       ran = r.next(0, stack.count()-1);       list.add(stack[ran]);       stack.removeat(ran);    }    return list; } 

the stack gets cardlist of 7 cards

should be:

this.stack.insertcards(getsevencards()); 

and create new instance of stack.

because cards null. fill them function first.

can't more things, because didn't give more information definitions. there should more codes.


Comments

Popular posts from this blog

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

xslt - Umbraco and EXSLT sets do not work -

php - How can I merge Nodes & Webform Submissions into instances of one general Content Type in Drupal 6? -