Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Please explain why I get this error...

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Please explain why I get this error...

    public class Votes 
    {
    	private int voteNumber;
    	private String candidateName;
    	private Votes next;
     
        public Votes(int v, String n) 
        {
        	voteNumber=v;
    		candidateName=n;
    		next=null;
        }
     
        public Votes addVote(int v, String n)
    	{
    		Votes c;
    		c=new Votes(v,n);
    		c.setNext(this);
    		return c;
    	}
     
        public String toString()
    	{
    		String r;
    		r=voteNumber + ". " + candidateName + "\n";
    		if (next != null)
    		{
    			return r=r + next.toString();
    		}
    		return r;	
    	}
    }
     
    public class Harness 
    {
    	public static void main(String[] args) 
    	{
    		Votes myVote;
    		myVote=new Votes(1,"Julia");
    		System.out.println(myVote.toString());
        }
    }

    JCreator Pro\MyProjects\Votes\Votes.java:27: error: cannot find symbol
    c.setNext(this);
    ^
    symbol: method setNext(Votes)
    location: variable c of type Votes
    1 error

    Process completed.

    Thanks alot


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Please explain why I get this error...

    cannot find symbol
    c.setNext(this);
    The compiler is complaining that you're trying to call a method, setNext(...) that the Votes class simply doesn't have. I happen to agree with the compiler since I don't see that method anywhere in your code.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Please explain why I get this error...

    Excellent. Thank you

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Please explain why I get this error...

    You're welcome!

Similar Threads

  1. [SOLVED] Can someone explain to me?
    By unleashed-my-freedom in forum Java Theory & Questions
    Replies: 5
    Last Post: July 3rd, 2012, 04:10 AM
  2. i need an explain please !
    By keep smiling in forum Java Theory & Questions
    Replies: 3
    Last Post: December 21st, 2011, 11:22 AM
  3. Replies: 1
    Last Post: December 13th, 2010, 05:13 AM
  4. Can anyone explain this code for me
    By gudwindavids in forum Object Oriented Programming
    Replies: 1
    Last Post: December 11th, 2009, 02:29 PM
  5. can anyone explain this?
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 12th, 2009, 02:51 AM