Results 1 to 5 of 5
  1. #1
    pondwire's Avatar
    pondwire is offline Member
    Join Date
    Jul 2011
    Location
    Somewhere in the Rockies
    Posts
    11
    Rep Power
    0

    Unhappy 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

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    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
    Java Code:
    Card c1 = new Card(Suit[i], Rank[j]);
    so the compiler says it cannot find that constructor.

    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.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    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.)

  4. #4
    pondwire's Avatar
    pondwire is offline Member
    Join Date
    Jul 2011
    Location
    Somewhere in the Rockies
    Posts
    11
    Rep Power
    0

    Lightbulb Thank you...

    OK, I think I get it a little better. I'm going to check over my Card class and insert a new constructor! I'm having trouble with how the classes interact, thus the error! Thanks, and I'll make the rank & suit lowercase, too....



    Quote Originally Posted by pbrockway2 View Post
    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.)

  5. #5
    pondwire's Avatar
    pondwire is offline Member
    Join Date
    Jul 2011
    Location
    Somewhere in the Rockies
    Posts
    11
    Rep Power
    0

    Default

    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

  1. Motion Detection desperate in need of help!!
    By Fabian fenech in forum Advanced Java
    Replies: 11
    Last Post: 04-12-2011, 11:57 AM
  2. Replies: 1
    Last Post: 01-20-2011, 05:59 PM
  3. help i'm desperate
    By AniMaind in forum New To Java
    Replies: 17
    Last Post: 01-08-2011, 02:05 AM
  4. Desperate for some help if possible :(
    By SBOSlayer in forum New To Java
    Replies: 1
    Last Post: 11-30-2010, 11:44 PM
  5. Multithreading + Networking (desperate)
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 11-07-2007, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •