-1

I'm getting the errors of "q cannot be resolved to a variable" and "Queue cannot be resolved to a type"... I'm not sure what I did wrong but if you guys can help, that would be great! The error is within q = new Queue<File>();

Queue.java:

package filesystem;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class LevelOrderIterator extends FileIterator<File> {
    
    public LevelOrderIterator(File rootNode) throws FileNotFoundException {
            if (!rootNode.exists())
                throw new FileNotFoundException();
            q = new Queue<File>();
            q.enqueue(rootNode);
    }

1 Answers1

0

Nothing defines the type 'Queue' in your program. Are you expecting to use the standard Java type ? Then write import java.util.Queue at the head of your file.

Nothing declares the variable 'q'. You need somewhere Queue<File> q = ...

Alas, the standard 'Queue' is not a class, but an interface. So you can't construct one with new Queue<File>(). You need to decide what sort of Queue you want. See the 'implementing classes' at the above documentation link.

It is possible you're not expecting the Java 'Queue' at all. In which case, only you know what you're expecting.

Since the Java Queue interface doesn't have an 'enqueue' method, maybe this is the issue. In which case, you've still got to get the Queue class definition from somewhere - so some sort of import statement may be needed. You definitely still need to declare q though.

passer-by
  • 1,103
  • 2
  • 4