gpt4 book ai didi

java - 表达式的类型必须是数组类型但它解析为 Card

转载 作者:行者123 更新时间:2023-11-29 03:24:22 26 4
gpt4 key购买 nike

我几乎完成了我的项目,但出现了这个错误:

“表达式的类型必须是数组类型但它解析为 Card”

行上写着:deck[i] = newCard[i]; 下面是代码:

public class Deck
{
//nextCard is used to keep count of which number card you are on in the deck.
public int nextCard;
private static final int DECK_SIZE = 52;

//deck is used to represent an entire deck of cards.
Card[] deck;
//hand is a pair of 7 cards; is generated by dealACard();
Card[] hand;

/**
* Default Constructor
*
* <hr>
* Date created: Feb 17, 2014
*
*
*/
public Deck ( )
{
int i;
nextCard = 0;

for(i=0;i<DECK_SIZE;i++)
{
Card newCard = new Card(i);

deck[i] = newCard[i];
}
}

我做错了什么?

最佳答案

删除数组括号以使用您刚刚创建的 Card 实例

deck[i] = newCard;
^

关于java - 表达式的类型必须是数组类型但它解析为 Card,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21842378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com