以下错误消息的含义是什么?
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "void", @ expected
Syntax error on token "]", :: expected after this token
Syntax error, insert "enum Identifier" to complete EnumHeader
它不喜欢的行是:
public static void main(String[] args) {
我的完整WIP代码,以防您需要查看上下文,如下所示。 Eclipse自动设置在该行中,我之前从未遇到过任何问题。
public class Card {
public class cardValue()
public static int suit;
public static int faceValue;
{
static int getfaceValue()
{
return faceValue;
}
setfaceValue(String faceValue)
{
cardFaceValue = faceValue;
return faceValue;
}
static int getSuit()
{
return suit;
}
setSuit(int suit)
{
cardSuit = suit;
return suit;
}
}
public static void main(String[] args) {
cardValue card1 = new cardValue();
// Suit values into strings for Hearts,Spades,Clubs, Diamonds
if (cardValue.getSuit() == 1)
{
System.out.print(" of Hearts");
}
if (cardValue.getSuit() == 2)
{
System.out.print(" of Spades");
}
if (cardValue.getSuit() == 3)
{
System.out.print(" of Clubs");
}
if (cardValue.getSuit() == 4)
{
System.out.print(" of Diamonds");
}
System.out.println(card1.getSuit());
}
}
答案 0 :(得分:0)
我真的建议在Java中搜索并学习类和对象。
但如果我得到了你想要做的事情,那就行了:
public class Card {
private int suit;
private int faceValue;
public Card (int suit, int faceValue) {
setSuit(suit);
setFaceValue(faceValue);
}
int getFaceValue () {
return faceValue;
}
void setFaceValue (int faceValue) {
this.faceValue = faceValue;
}
int getSuit () {
return suit;
}
void setSuit (int suit) {
this.suit = suit;
}
public static void main (String[] args) {
Card card = new Card(1, 4);
System.out.print(card.getFaceValue());
// Suit values into strings for Hearts,Spades,Clubs, Diamonds
if (card.getSuit() == 1) {
System.out.println(" of Hearts");
} else if (card.getSuit() == 2) {
System.out.println(" of Spades");
} else if (card.getSuit() == 3) {
System.out.println(" of Clubs");
} else if (card.getSuit() == 4) {
System.out.println(" of Diamonds");
}
}
}
答案 1 :(得分:-1)
如果你在类声明中有导入,需要在你的类声明之前来。
import java.io.*;
import java.util.*;
或类似的
检查您的缩进,这是不正确的。您可能会失去平衡。
class Card {
private int suit;
private int faceValue;
public Card (int suit, int faceValue)
{
setSuit(suit);
setfaceValue(faceValue);
}
int getfaceValue () {
return faceValue;
}
void setfaceValue (int faceValue) {
this.faceValue = faceValue;
}
int getSuit () {
return suit;
}
void setSuit (int suit) {
this.suit = suit;
}
public static void main (String[] args) {
Card card = new Card(1, 4);
System.out.print(card.getfaceValue());
// Suit values into strings for Hearts,Spades,Clubs, Diamonds
if (card.getSuit() == 1) {
System.out.println(" of Hearts");
} else if (card.getSuit() == 2) {
System.out.println(" of Spades");
} else if (card.getSuit() == 3) {
System.out.println(" of Clubs");
} else if (card.getSuit() == 4) {
System.out.println(" of Diamonds");
}
}
}