Results 1 to 5 of 5
- 07-19-2011, 07:35 AM #1
Desperate: How do I fix this error?
Hello, I am new to the Forum and hope I can get some help on this error. I received only one error:
"Game.java:71: cannot find symbol
symbol : constructor Card(java.lang.String,int)
location: class Card
Card c1 = new Card(Suit[i], Rank[j]);"
in my memory game. Now, at the top of the Game class, I have:
private int numCards;
final int maxCards = 20;
private Player[] players;
final private String[] Suit = {"CLUBS", "DIAMONDS", "HEARTS", "SPADES"};
final private int[] Rank = {1,2,3,4,5,6,7,8,9,10,11,12,13};
private Card[] cards;
so you can see I've listed Card array. I also have a separate Card class file created. Is this error asking for something else than that? I appreciate any help. Thanks.
Pondwire
- 07-19-2011, 07:42 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
In your Card class, you don't have a constructor that takes a String and an int but you are trying to use such a constructor with the line
so the compiler says it cannot find that constructor.Java Code:Card c1 = new Card(Suit[i], Rank[j]);
Now if you read the error message that you got again you will see that it was already giving you hints about what the problem is so in future you should try to read and understand those error messages so you can solve the problems on your own.
- 07-19-2011, 07:45 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
When you say "Card c1 = new Card(Suit[i], Rank[j]);" you are creating a new Card instance with a suit of Suit[i] (a String) and a rank of Rank[i] (an int). What the compiler message is saying is that you haven't actually got a Card constructor that takes a String and an int as arguments. Basically you have to write one:
-----Java Code:class Card { public Card(String suit, int rank) { // do something with suit and rank } }
It would be a good idea to follow Java coding conventions and begin variables with a lowercase letter. It may be the case that Suit and Rank "feel" a little different to players but at the moment you are coding them all as simple arrays. (The difference is that games will tend to have different players but will always involve the same suits and ranks. There are Java language constructions to allow you to express this fact, but you do not necessarily need to understand or use them to begin with.)
- 07-19-2011, 08:21 AM #4
- 07-19-2011, 08:25 AM #5
Thanks for both of your replies! I haven't been getting a lot of help where I go to school (haven't found a real computer science tutor), so I'm a little behind at learning what the big picture is for the interaction of classes and methods. Thank you so much for your help, though. I just needed someone to say what the compiler was looking for, and now I think I get it! Going to work on it...
Similar Threads
-
Motion Detection desperate in need of help!!
By Fabian fenech in forum Advanced JavaReplies: 11Last Post: 04-12-2011, 10:57 AM -
PLEASE SOMEONE HELP ME =( database.. im desperate
By santa in forum New To JavaReplies: 1Last Post: 01-20-2011, 04:59 PM -
help i'm desperate
By AniMaind in forum New To JavaReplies: 17Last Post: 01-08-2011, 01:05 AM -
Desperate for some help if possible :(
By SBOSlayer in forum New To JavaReplies: 1Last Post: 11-30-2010, 10:44 PM -
Multithreading + Networking (desperate)
By bluebarca in forum New To JavaReplies: 1Last Post: 11-07-2007, 02:14 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks