problem with instantiating object
Hi, I'm getting an error that an object cannot be instantiated in the following code
Code java:
public class Prog2 {
/**
* @param args the command line arguments
*/
public static void main(String [] args){
Card card = new Card(Rank.QUEEN, Suit.SPADES);
//System.out.println(card);
//System.out.println(card.toStringShort());
System.out.println("_____________________________");
/* Deck deck = new Deck();
deck.shuffle();
for (int i = 0; i < 50; ++i) {
System.out.println(deck.dealCard());
}
System.out.println(deck); //prints the remaining cards
System.out.println("_____________________________");
Shoe shoe = new Shoe(4);
shoe.shuffle();
for (int i = 0; i < 50; ++i) {
System.out.println(shoe.dealCard());
}
System.out.println("_____________________________"); */
}
}
class Card{ //outputs info for a single instance of a card
public int SingleCard;
public int SingleSuit;
public Card(int x, int y) {
SingleCard = x;
SingleSuit = y;
}
class Deck{
}
class Shoe{
}
class Rank{
public static final int ACE=0;
public static final int TWO=1;
public static final int THREE=2;
public static final int FOUR=3;
public static final int FIVE=4;
public static final int SIX=5;
public static final int SEVEN=6;
public static final int EIGHT=7;
public static final int NINE=8;
public static final int TEN=9;
public static final int JACK=10;
public static final int QUEEN=11;
public static final int KING=12;
}
class Suit{
public static final int SPADES = 1;
public static final int HEARTS = 0;
public static final int CLUBS = 3;
public static final int DIAMONDS = 2;
}}
I keep getting this error:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - internal error; cannot instantiate Card(int,int) at prog2.Card to ()
at prog2.Prog2.main(Prog2.java:7)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
---
When I tried replacing Rank.QUEEN and Suit.SPADES with integer values instead the program had no problem.
Re: problem with instantiating object
Do you want Rank and Suit to be inner classes of Card? If so (as is currently written), you need to specify this when referring to them (eg Card.Rank.QUEEN)
Re: problem with instantiating object
I'm trying to avoid that, the idea is to pass values from QUEEN in the rank class and SPADES in the Suit class into the the new Card(int, int) statement instead of something like new Card(3,4)
If I wrote something in the code that means that, then maybe that's my error.
Re: problem with instantiating object
Quote:
Originally Posted by
Goldfinch
I'm trying to avoid that,
That is what is written. Check your brackets to create separate classes, or better yet pull all those classes into their own class files.
Re: problem with instantiating object
I found the error on this one. You were right, it was the brackets.