2

I've looked all around and it seems I have the proper syntax:

QueueOfChars queue = new QueueOfChars();
QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode();

However I get a compiling error with the charNode object I try to create

Driver3.java:22: error: constructor QueueOfCharsNode in class
QueueOfChars.QueueOfCharsNode cannot be applied to given types;
QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode();


required: char
found: no arguments
reason: actual and formal argument lists differ in length
1 error

It's getting this error because I have a QueueOfCharsNode(char ch)

public class QueueOfChars{

      public class QueueOfCharsNode{
         QueueOfCharsNode next;
         QueueOfCharsNode prev;
         char c;

         public QueueOfCharsNode(char ch){ //line causing the error
            c = ch; 
            next = prev = null;
         }

How do I get it to just read the "public class QueueOfCharsNode" line when I'm making the object for it?

4

2 回答 2

5

您缺少一个无参数构造函数。

您需要一个构造函数声明,如下所示:

public QueueOfCharsNode() { }

在你的QueueOfCharsNode课上。

于 2012-11-14T00:36:27.517 回答
1
QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode();

您的内部类 QueueOfCharsNode 在其构造函数中需要 char 作为参数。尝试

QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode('c');//some character that you wanna pass

或在您的内部类中创建一个无参数构造函数,例如。

public UueueOfCharsNode() {

}

QueueOfChars.QueueOfCharsNode charNode = queue.new QueueOfCharsNode();

在这种情况下可以工作

于 2012-11-14T00:37:45.697 回答