Arrays 它一直在说java.lang.NullPointerException。试图弄清楚是什么。有人帮忙吗?
我一直在试图找出代码的错误。有什么我做得不对的吗 公共课2{ 公众卡[]牌组Arrays 它一直在说java.lang.NullPointerException。试图弄清楚是什么。有人帮忙吗?,arrays,nullpointerexception,Arrays,Nullpointerexception,我一直在试图找出代码的错误。有什么我做得不对的吗 公共课2{ 公众卡[]牌组 public void CreateDeck() { String[] suit = { "Spades", "Hearts", "Diamonds", "Clubs" };//Array for suit int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // Array for rank for (int i = 0
public void CreateDeck() {
String[] suit = { "Spades", "Hearts", "Diamonds", "Clubs" };//Array for suit
int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // Array for rank
for (int i = 0; i <suit.length ; i++) {//Looping the suit array
for (int n = 0; n < number.length; n++) { // Looping the number array
Card c = new Card(suit[i], number[i]); //Calling the constructor from my card class
if (deck[i] == null) {
deck[i] = c;
}
}
}
}
public void displayDeck() {
for (int i = 0; i <deck.length; i++) {
if (deck[i] != null) {
deck[i].display(); // Calling the display method from my card class.
}
}
}
public void CreateDeck(){
String[]suit={“黑桃”、“红心”、“钻石”、“梅花”};//suit数组
int[]number={1,2,3,4,5,6,7,8,9,10,11,12,13};//秩数组
对于(inti=0;i我猜你的牌组是空的
public class deck2 {
public Card[] deck; // deck is null
public deck2() {
deck = new Card[52]; // now it's not.
}
public void CreateDeck() {
String[] suit = { "Spades", "Hearts", "Diamonds", "Clubs" };//Array for suit
int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // Array for rank
for (int i = 0; i <suit.length ; i++) {//Looping the suit array
for (int n = 0; n < number.length; n++) { // Looping the number array
Card c = new Card(suit[i], number[i]); //Calling the constructor from my card class
if (deck[i] == null) {
deck[i] = c;
}
}
}
}
公共类deck2{
公共卡[]牌组;//牌组为空
公众谘询委员会2(){
牌组=新牌[52];//现在不是了。
}
公共void CreateDeck(){
String[]suit={“黑桃”、“红心”、“钻石”、“梅花”};//suit数组
int[]number={1,2,3,4,5,6,7,8,9,10,11,12,13};//秩数组
对于(int i=0;我调试了吗?发生了什么?在哪里?异常会确切地告诉您它发生在哪一行上。它是哪一行?以及在调试器中设置断点并单步执行代码时会发生什么?