We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,987 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Cannot resolve symbol

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);
    }

[I]some other methods omitted [/I]

Code tags added. -Narue
-------------------------------------------------------------------------

3
Contributors
4
Replies
7 Hours
Discussion Span
8 Years Ago
Last Updated
5
Views
drunkpanda
Newbie Poster
5 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Where is your Item class?

stupidenator
Junior Poster
192 posts since Mar 2005
Reputation Points: 18
Solved Threads: 4
Skill Endorsements: 0

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

item class
-----------------------------------------------

import java.util.HashMap;
import java.util.Set;
import java.util.Iterator;


public class Item
{
    private String description;
    private String name;
    private int weight;
    private boolean moveable;


    /**
     * Constructor for objects of class Item.
     */
    public Item(String myDescription, String myName, int myWeight, boolean itemMoveable) 
    {
        this.description = myDescription;
        this.name = myName;
        this.weight = myWeight;
        this.moveable = itemMoveable;       
    }

    /**
     * Return the description of the item (the one that was defined
     * in the constructor).
     */
    public String getDescription()
    {
        return description;
    }
    
    /**
     * Return the name of the item (the one that was defined
     * in the constructor).
     */
    public String getName()
    {
        return name;
    }
    
    public boolean isMoveable()
    {
        return (moveable == false);
    }
    
    /**
     * Return the weight of the item 
     */
    public int getWeight()
    {
        return weight;
    }
    
}

Code tags added. -Narue

drunkpanda
Newbie Poster
5 posts since Apr 2005
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

jwenting
duckman
Team Colleague
8,522 posts since Nov 2004
Reputation Points: 1,656
Solved Threads: 345
Skill Endorsements: 19

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.

stupidenator
Junior Poster
192 posts since Mar 2005
Reputation Points: 18
Solved Threads: 4
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0711 seconds using 2.78MB