944,123 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 7867
  • Java RSS
Apr 1st, 2005
0

Cannot resolve symbol

Expand Post »
recently, i bought a textbook call "Objects first with java" for self study. at the chapter 7, design a "Command Line Game" and a exercise ask me to put more functions in the game, as i do so i encounter many problems, and one of the problem as sohowing below, i wonder if anybody can help me

when i add these two codes :

Item textbook = new Item("this is a Java textbook",5);
office.addItem("Textbook",textbook);

the complier tell me:
Cannot resolve symbol constructor Item (java.jang.string,int)


can somebody please tell me what wrong with it thank you very much
---------------------------------------------------------------------------
public class Game 
{
    private Parser parser;
    private Room currentRoom;
    private Player currentPlayer;
   
   
        
    /**
     * Create the game and initialise its internal map.
     */
    public Game() 
    {
        createRooms();
        parser = new Parser();
        
        currentPlayer = new Player("Mark",currentRoom);
    }

    /**
     * Create all the rooms and link their exits together.
     */
    private void createRooms()
    {
        Room outside, theatre, pub, lab, office, cellar;
      
        // create the rooms
        outside = new Room("outside the main entrance of the Polytechnic");
        theatre = new Room("in a lecture theatre");
        pub = new Room("in the campus pub");
        lab = new Room("in a computing lab");
        office = new Room("in the computing admin office");
        cellar = new Room("in the cellar");
        // initialise room exits
        outside.setExit("east", theatre);
        outside.setExit("south", lab);
        outside.setExit("west", pub);

        theatre.setExit("west", outside);

        pub.setExit("east", outside);

        lab.setExit("north", outside);
        lab.setExit("east", office);
        

        office.setExit("west", lab);
        office.setExit("down", cellar);
        cellar.setExit("up", office);
        currentRoom = outside;  // start game outside
        
        // add items 
        Item textbook = new Item("this is a Java textbook",5);
        office.addItem("Textbook",textbook);
    }

some other methods omitted 
Code tags added. -Narue
-------------------------------------------------------------------------
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
drunkpanda is offline Offline
5 posts
since Apr 2005
Apr 1st, 2005
0

Re: Cannot resolve symbol

Where is your Item class?
Reputation Points: 18
Solved Threads: 4
Junior Poster
stupidenator is offline Offline
192 posts
since Mar 2005
Apr 1st, 2005
0

Re: Cannot resolve symbol

sorry i am just new and i am not sure what might make a good post

item class
-----------------------------------------------
Java Syntax (Toggle Plain Text)
  1. import java.util.HashMap;
  2. import java.util.Set;
  3. import java.util.Iterator;
  4.  
  5.  
  6. public class Item
  7. {
  8. private String description;
  9. private String name;
  10. private int weight;
  11. private boolean moveable;
  12.  
  13.  
  14. /**
  15.   * Constructor for objects of class Item.
  16.   */
  17. public Item(String myDescription, String myName, int myWeight, boolean itemMoveable)
  18. {
  19. this.description = myDescription;
  20. this.name = myName;
  21. this.weight = myWeight;
  22. this.moveable = itemMoveable;
  23. }
  24.  
  25. /**
  26.   * Return the description of the item (the one that was defined
  27.   * in the constructor).
  28.   */
  29. public String getDescription()
  30. {
  31. return description;
  32. }
  33.  
  34. /**
  35.   * Return the name of the item (the one that was defined
  36.   * in the constructor).
  37.   */
  38. public String getName()
  39. {
  40. return name;
  41. }
  42.  
  43. public boolean isMoveable()
  44. {
  45. return (moveable == false);
  46. }
  47.  
  48. /**
  49.   * Return the weight of the item
  50.   */
  51. public int getWeight()
  52. {
  53. return weight;
  54. }
  55.  
  56. }
Code tags added. -Narue
Reputation Points: 10
Solved Threads: 0
Newbie Poster
drunkpanda is offline Offline
5 posts
since Apr 2005
Apr 1st, 2005
0

Re: Cannot resolve symbol

Well, you don't have a constructor matching the parameter list you're using when you try to create an Item.
That's why you get that error, the compiler cannot find a symbol (meaning a reference to something) with the required signature in the Item class.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Apr 1st, 2005
0

Re: Cannot resolve symbol

in the Item class constructor, you have
public Item(String myDescription, String myName, int myWeight, boolean itemMoveable)
... you're asking for 2 Strings, an int, and a boolean... but then when you construct the Item in the game code, you are only sending it one String, and an int.. they both need to match.
Reputation Points: 18
Solved Threads: 4
Junior Poster
stupidenator is offline Offline
192 posts
since Mar 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: a Java GUI based program using Swing classes, Vat
Next Thread in Java Forum Timeline: in need of a function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC