Eclipse说,构造函数未定义,但其定义为(Java) [英] Constructor undefined, says Eclipse, but its defined (Java)

查看:104
本文介绍了Eclipse说,构造函数未定义,但其定义为(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!

我收到错误消息:未定义构造函数Node(int)

具有主要方法的类:

package LLP;

public class LinkedList2Test {

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

    test.add(13);
    test.add(10);
    test.add(21);
}
}


LinkedList2类

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;
        tail=node;
    }
}
}


Node类

package LLP;

public class Node {
int data;
Node nextNode;

public Node (int data){
    this.data = data;
}
}


如我所见,在主方法中,我输入一个整数,例如'13'.add方法接收此整数并将其称为数据"我想用该数据"创建节点Node的构造函数只需要一个整数,即为数据",因此现在为13,例如


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...

非常感谢

推荐答案

它应该可以工作.我想可能是因为您提供了一个构造函数后没有保存Node类,所以出现了错误.

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

与@ mypal125一样,您可能还希望在 LinkedList2Test 类中使用 static 主方法.更改后,尝试运行(运行也会自动保存所有更改)您的程序,然后查看是否仍然存在错误.

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.

这篇关于Eclipse说,构造函数未定义,但其定义为(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆