[英]Method not being recognized even when declared
So, I am creating a project of a basic "arcade".所以,我正在创建一个基本的“拱廊”项目。 I have cards which are passed into games(methods).
我有传递到游戏中的卡片(方法)。 I created a method in my Card class to have the ability to chose which cards to use for the games.
我在 Card 类中创建了一个方法,以便能够选择用于游戏的卡片。
public Card choosecard(Card firstCard, Card secondCard) {
Scanner input = new Scanner(System.in);
Card chosen = new Card();
boolean check = false;
while(check == false) {
System.out.println("What card would you like to use?\n 1. " + firstCard.name + "\n 2. " + secondCard.name);
int answer = Integer.parseInt(input.nextLine());
if(answer == 1) {
chosen = firstCard;
check = true;
}
else if(answer == 2) {
chosen = secondCard;
check = true;
}
else {
}
} //while
return chosen;
After creating this method I tried calling it in this context:创建此方法后,我尝试在此上下文中调用它:
public static void terminal(Card card1, Card card2) {
boolean loop = true;
while(loop == true) {
System.out.println("What would you like to do?\n1. Guess Game\n2. Transfer\n3. Prizes\n4. Cancel");
Scanner take = new Scanner(System.in);
int answer = Integer.parseInt(take.nextLine());
switch(answer) {
case 1:
Game.GuessGame(Card.chooseCard(card1, card2));
}
}
I thought that it may be because im trying to call a method in the parameters of another method.我认为这可能是因为我试图在另一个方法的参数中调用一个方法。 So I tried calling it from other classes but it still gives the cannot find symbol error.
所以我尝试从其他类调用它,但它仍然给出了找不到符号的错误。
Thank you.谢谢你。
public Card choosecard(Card firstCard, Card secondCard)
Its not a static method.它不是静态方法。
Game.GuessGame(Card.chooseCard(card1, card2));
But Card.chooseCard(card1, card2)
means you are calling it statically.但是
Card.chooseCard(card1, card2)
意味着您正在静态调用它。
Consider making it static or calling via object.考虑将其设为静态或通过对象调用。
Card.chooseCard(card1, card2)
means calling a static method. Card.chooseCard(card1, card2)
表示调用静态方法。 You may want to declare chooseCard
as你可能想声明
chooseCard
为
public static Card choosecard(Card firstCard, Card secondCard)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.