类中的Java'构造函数不能应用于给定类型''required:找不到任何参数:String' [英] Java 'constructor in class cannot be applied to given types' 'required: no arguments found: String'

查看:1053
本文介绍了类中的Java'构造函数不能应用于给定类型''required:找不到任何参数:String'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行一项任务,我必须从头开始创建一个链表,并在编译类Node中的构造函数Node不能应用于给定类型时时遇到错误;

I'm working on an assignment where I have to create a linked list from scratch and have come across an error when compiling that the "constructor Node in class Node cannot be applied to given types;"

这就是我正在尝试的,错误说:

This is what I'm trying, the error says:

必需:没有参数
found:string

required: no arguments found: string

然而我无法看到我出错的地方,因为我的Node构造函数需要一个字符串?

Yet I cannot see where I am going wrong as my constructor for Node requires a string?

public class Node {
    String data;
    Node next;

    public void Node(String x) {
        data = x;
        next = null;
    }
}



public class stringList {
    private Node head;
    private int count;

    public void stringList() {
        head = null;
        count = null;
    }

    public void add(String x) {
        Node temp = new Node(x);
    }

这是编译器显示的错误的屏幕截图

推荐答案

这:

public void Node(String x) {
    data = x;
    next = null;
}

应为:

   public Node(String x) {
        data = x;
        next = null;
    }

目前你有一个默认构造函数(没有arguments),在没有任何显式构造函数的情况下隐式定义。

Currently you have a default constructor (taking no arguments), which is implicitly defined in the absence of any explicit constructors.

这篇关于类中的Java'构造函数不能应用于给定类型''required:找不到任何参数:String'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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