Please explain why I get this error...
Code :
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
Re: Please explain why I get this error...
Quote:
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.
Re: Please explain why I get this error...
Re: Please explain why I get this error...