Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"cannot resolve symbol" error

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
US
Hello,

I'm in the middle of creating a simple java-based game (in the mold of the old "Battleship" board game). I have built several class files within a package called "maritime" that determine the names and locations of the ships and islands that will lay over a grid (based on x and y coordinates). For the most part, I think my code is correct but I seem to have a symbol conflict between a couple of the classes I've produced. I have a class called "Location" that simply takes in an x and a y coordinate and returns a string in the mold of "(x,y)". High up in my class hierarchy, I have a class called "SimObject" which generally takes in a name and location for the object to be produced (island or ship). But when I try to create a location class object within the SimObject class file, I get a compile-time error that says "cannot resolve symbol" and lists "class Location" and "class maritime.SimObject" as the culprits. The Location.java file compiles just fine (though it's outside the class hierarchy) but the other files don't and it all seems to stem from Location.java. Does anyone have any ideas? I have my code posted below.

Thanks,
Jisoo22


Location.java
Code:
package maritime;

public class Location
{
	int co1;
	int co2;

	public Location (int x, int y)
	{
		co1 = x;
		co2 = y;
	}

	public String toString()
	{
		String temp = "(" + co1 + ", " + co2 + ")";
		return temp;
	}

}//class Location

simObject.java
Code:
package maritime;

abstract public class SimObject
{
	protected String name;
	protected Location loc = new Location(0,0);

	public SimObject(String name, Location location)
	{
		name = name;
		loc = location;

		System.out.println("SimObject " + name + " constructed");
	}
	abstract public String toString();
}//class SimObject
 
Nevermind, figured it out. Turns out it was a CLASSPATH issue. I have a new question now, it turns out that I need to use a private class constructor in one of my java files (incidently the one that uses all the other class files created to run the game). Since constructors are usually public, what could happen if it's declared private? I know that I can't instantiate a class object of that particular class directly anymore like before. How would I instantiate an object of a class that has a private constructor? I.E. My old statement with a public constructor was:

MaritimeModel m1 = new MaritimeModel();

But that is no longer possible since MaritimeModel() is private.

Thanks,
Jisoo22
 
You cannot.If your constructor method is private you should build your methods as static in that class.After that you may reach your methods directly. Salih Sipahi
Software Engineer.
City of Istanbul Turkey
ssipahi@yonbilgi.com
 
why do you have to make the constructor private, if you dont mind me asking? -------------------------------------------
There are no onions, only magic
-------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top