//This is the error that i have Exception in thread "main" java.lang.NullPointerException
//at CardTest.main(CardTest.java:16)
/**
* @(#)CardTest.java
*
*
* @Robert Coughlin
* @version 1.00 2010/10/15
*/
//this is the main
public class CardTest {
public static void main(String [] args) {
Card [] randomCard=new Card[20];
for(int i= 0; i<20; i ++)
{
randomCard[i].flipCard();//this is the line that i get the error in
randomCard[i].getSuit();
}
for(int y= 0; y<20; y ++)
{
System.out.println(randomCard[y].toString());
}
}
}
/**
* @(#)Card.java
*
*
* @Robert Coughlin
* @version 1.00 2010/10/15
*/
import java.util.*;
public class Card {
private String Suit;
private int FaceValue;
public Card() {
Suit="";
FaceValue=0;
}
public int flipCard(){
Random randGen= new Random( );
FaceValue= randGen.nextInt(11)+1;
return FaceValue;
}//ends flipCard
public String getSuit(){
int value = 0;
Random randGen= new Random( );
value= randGen.nextInt(4)+1;
System.out.println(value);//oputs value of random number
if(value==1)
Suit="Spades";
if(value==2)
Suit="Diamonds";
if(value==3)
Suit="Hearts";
if(value==4)
Suit="Clubs";
return Suit;
}//ends getSuit
public String toString(){
String str;
str="Face Value: " + FaceValue +"\n"
+ "Suit: " + Suit;
return str;
}//ends toString
}//ends class
rcogq7 0 Newbie Poster
kramerd 29 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.