java.lang.IllegalArgumentException: n must be positive in deck class
<p>I'm making a card game and I'm getting the error that n must be positive. I did some research and it means that (cards.size) is equal or less than 0 I believe, but I don't understand how to make my code work, something must be wrong.</p>

<p>Code:</p>

<pre><code>public class Deck
{
public ArrayList &lt;Card&gt; cards;
Deck()
{
    cards = new ArrayList&lt;&gt;();
    for (int a = 0; a &lt; 52; a++)
    {           
            cards.add(new Card(a));         
    }
}

public Card PlayerCardDraw ()
{
    Random generator = new Random ();
    int index = generator.nextInt (cards.size ());
    return cards.remove (index);

}
</code></pre>

<p>How can I fix my array list so i don't get this error? it relates back to Card so I'll post that code too, I know something isn't right in my Card class but I don't know if that's the problem or not.</p>

<pre><code>public class Card
{
int c = 52;
int cardpath[] = new int[c];

Card ()
{

}


public Card(int c)
{
    this.c = c;
}

public int getCardPath()
{
return cardpath[c];
}   
}
</code></pre>

<p>Error message:</p>

<pre><code>java.util.Random.nextInt(Unknown Source) at Cards.Deck.PlayerCardDraw(Deck.java:21)
line 21 is int index = generator.nextInt (cards.size ());
</code></pre>

<p>EDIT: I did what Nankumar Tekale said and it's saying what you guys predicted: It's drawing more than 52 cards. What I don't understand is the error is popping up at</p>

<pre><code>for (int i = 0 ; i &lt; 4 ; i++)
    {
        C = deck.P1CardDraw ();
        card [cardNum].draw (i*75+100, 400); //Error line
        cardNum++;                   
    }
</code></pre>

<p>my P1CardDraw() class</p>

<pre><code>public ArrayList &lt; Card &gt; p1Hand;
public ArrayList &lt; Card &gt; P1CardDraw ()
{

    p1Hand = new ArrayList &lt; &gt; ();
    p1Hand.add (PlayerCardDraw ());
    return p1Hand;
}
</code></pre>
