Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
First off let me say that I am new to Java and I have researches about this error as it seems it's a common one, but I still haven't found the solution. Here is my code:
Java
public class Test3 {
    
    
    public static void main(String[] args) {
        
        WhiteHouseTour tour = new WhiteHouseTour();
        System.out.println(tour.getRooms( ));
        System.out.println();
        System.out.println(tour);
        
        Visitor v1 = new Visitor("Smirnov, Alex", "M", 35, "Russia");
        Visitor v2 = new Visitor("Smith, Stan", "M", 31, "United States");
        Visitor v3 = new Visitor("Malone, Maggie", "F", 32, "United States");
        Visitor v4 = new Visitor("Zhao, George", "M", 29, "China");
        Visitor v5 = new Visitor("Whiting, Whitney", "F", 32, "Canada");
        

        tour.setVisitor(v1);
        tour.setVisitor(v2);
        tour.setVisitor(v3);
        tour.setVisitor(v4);
        
        //System.out.println(tour);
    }
}


And here is my code from the source file that sets the visitors:
Java
public Visitor[] getVisitors( )
	{
			return visitors;
	}
	
	public void setVisitors(Visitor[] theVisitors)
	{
			visitors = theVisitors;
	}
	
	public int getNumVisitors( )
	{
			return numVisitors;
	}
	
	public void setNumVisitors(int theNumVisitors)
	{
			numVisitors = theNumVisitors;
	}


And the error I am getting is this:

Test3.java:20: error: cannot find symbol
        tour.setVisitor(v1);
            ^
  symbol:   method setVisitor(Visitor)
  location: variable tour of type WhiteHouseTour
Test3.java:21: error: cannot find symbol
        tour.setVisitor(v2);
            ^
  symbol:   method setVisitor(Visitor)
  location: variable tour of type WhiteHouseTour
Test3.java:22: error: cannot find symbol
        tour.setVisitor(v3);
            ^
  symbol:   method setVisitor(Visitor)
  location: variable tour of type WhiteHouseTour
Test3.java:23: error: cannot find symbol
        tour.setVisitor(v4);
            ^
  symbol:   method setVisitor(Visitor)
  location: variable tour of type WhiteHouseTour
4 errors


What I have tried:

I have tried reading on this issue and fixing it myself but so far I haven't been successful. I also tried setting visitors in a different way but that hasn't worked for me either.
Posted
Updated 4-Jun-17 21:29pm

1 solution

The message is telling you what line the error occurs on, and what the problem is. Go to line 20 and look at the statement; where is the definition of WhiteHouseTour?

Your time would be better spent working through the Java Tutorials, which Google will find for you.
 
Share this answer
 
Comments
CPallini 5-Jun-17 5:03am    
5.
dc_14 5-Jun-17 9:27am    
You can just tell me that you don't know how to fix it buddy but thanks for your comment.
Richard MacCutchan 5-Jun-17 9:35am    
Of course I know how to fix it. You create a proper WhiteHouseTour class and import its definition into your program. Like I said, go and work through the Java Tutorials and learn the basics of Java programming.
dc_14 5-Jun-17 10:33am    
I'm learning this in school right now and I don't want to learn new techniques, at least not yet. Once I feel more comfortable with Java then I will teach myself new topics.
Richard MacCutchan 5-Jun-17 11:27am    
Then maybe you should talk to your teacher rather than posting questions here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900