EDIT: [SOLVED] Thanks again -- I think I learned something new that I should have known about arrays:
When creating object[] something = new object[int]; something all point to null and need to be explicitly told what to point to.
After browsing through possible solutions I still haven't found the answer to my question:
I am attempting to call a method from another class but it seems that it isn't initialized/instantiated. I thought I did but apparently not? I keep getting a NPE
Main method (countingCards.java):
public class deck {
card[] deckCard = new card[51];
/** Rules for the deck of card.
* 1. You cannot have same value of cards with same suite.
* --- i.e) no two queens of hearts
**/
public void test() {
System.out.println( deckCard.length );
System.out.println( deckCard[1].getValue() );
}
Card class:
public class card {
private String value = "hello";
private String suite = "suiteHello";
// Method to return value
public String getValue() {
return value;
}
// Method to return suite
public String getSuite() {
return suite;
}
// Method to set value
public void setValue(String s) {
value = s;
}
// Method to set suite
public void setSuite(String s) {
suite = s;
}
// Method to test
public void testing() {
value = "test";
System.out.println( value );
}
}
deck class:
public class deck {
card[] deckCard = new card[51];
/** Rules for the deck of card.
* 1. You cannot have same value of cards with same suite.
* --- i.e) no two queens of hearts
**/
public void test() {
System.out.println( deckCard.length );
System.out.println( deckCard[1].getValue() );
}
}
The Exception I get says
Exception in thread "main" java.lang.NullPointerException
at deck.test(deck.java:11)
at countingCards.main(countingCards.java:4)
Anyone have any idea what's going on with my code?
null. Given that, what do you thinkdeckCard[1].getValue()does?