Strange error message - linked lists (again)
I have to keep at this linked list thing if I'm ever going to really understand it!!
I have created a method to create a linked list via user input. I'm receiving only one strange ERROR, which states:
"This method must return a result of of type ListADT.Node."
And I have just started building my class ListADT...
class ListADT{
public Node createList(int aNumber){// THIS IS WHERE THE ERROR POINTS
/*
* integer variable aNumber is the length of the list user wishes to create.
*/
Scanner console =new Scanner(System.in);
int number;// declare variable number as an integer.
Node newNode =new Node();// declare and initialize newNode.
Node first =new Node();// declare and initialize first.
Node last =new Node();// delcare and initizlize last.
try
{
for(int i = 0; i <= aNumber; i++){// for loop to enter numbers to build list.
System.out.println("Please enter an integer: ");// prompt user.
number = console.nextInt();// assign user input to variable number.
newNode.info = number;// assign number to newNode;
if(first ==null){// checks to see if Node first is a null value.
first = newNode;// if true, then this node is the first and last node in the list.
last = newNode;
}
else{// if first is not null, then newNode is placed at the end of the list.
last.link = newNode;
last = newNode;
}
}
return first;
}
catch (InputMismatchException imeRef)//Catches non-integer values
{
System.out.println("You entered a non-Integer! " + imeRef.toString());//Prints error message
}
}

