What does the following error messages mean?
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
The line it does not like is:
public static void main(String[] args) {
My full WIP code in case you need to see it for context is as follows. Eclipse automatically sets in that line and I have never had issues with it before.
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());
}
}
I really recommend searching around and learning about classes and objects in Java.
But if I get what you're trying to do, this will just work:
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");
}
}
}
IF you have imports inside class declaration, need to come before your class declaration.
import java.io.*;
import java.util.*;
or similar
Check your indentation, which is incorrect. You may have {} out of balance.
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");
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.