| | |
Cannot resolve symbol
![]() |
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
Solved Threads: 0
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
---------------------------------------------------------------------------
Code tags added. -Narue
-------------------------------------------------------------------------
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 -------------------------------------------------------------------------
•
•
Join Date: Apr 2005
Posts: 5
Reputation:
Solved Threads: 0
sorry i am just new and i am not sure what might make a good post
item class
-----------------------------------------------
Code tags added. -Narue
item class
-----------------------------------------------
Java Syntax (Toggle Plain Text)
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; } }
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.
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
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.
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.
![]() |
Similar Threads
- Cannot Resolve Symbol (Java)
- cannot resolve symbol symbol : variable JoptionPane (IT Professionals' Lounge)
- Still cannot resolve symbol (Java)
- Cannot resolve symbol (Java)
- "Cannot Resolve Symbol" (Java)
- "cannot resolve symbol"problem (Java)
- Cannot resolve symbol message appears when compiling (Java)
Other Threads in the Java Forum
- Previous Thread: a Java GUI based program using Swing classes, Vat
- Next Thread: in need of a function
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






