user3435407 user3435407 - 6 months ago 24
Java Question

Constructor undefined, says Eclipse, but its defined (Java)

I don't get it, why is this constructor not defined. I check some other similar questions here, but there was always the problem, that they wanted to call the constructor without parameters, while the constructor had parameters. But I don't see this problem in my code. Could you please help me? Thank you!

I get the error message:

The constructor Node(int) is undefined

The class with the main method:

package LLP;

public class LinkedList2Test {

public void main (String args[]){
LinkedList2 test = new LinkedList2();


The LinkedList2 class

package LLP;

public class LinkedList2 {

Node head;
Node tail;

public void add(int data){

**Node node = new Node(data);**// **THE PROBLEM is here**

if (tail == null){
tail = node;
head = node;
} else {
tail.nextNode = node;

The Node class

package LLP;

public class Node {
int data;
Node nextNode;

public Node (int data){ = data;

As I see, in the main method I give in an integer, for example '13'.
The add method receives this integer and calls it as 'data'
And I would like to create the node with that 'data'
Node's constructor needs just one integer, which would be 'data' so now 13 for example

Why does it not work, i dont get it...

Many Thanks


It should work. I guess it could be that you didn't save your Node class after you provided a constructor hence the error.

Also as @mypal125 you probably want static main method in your LinkedList2Test class. After changing that try to run (running also automatically saves all the changes) your program and see if there is still an error.