1

I have the following Subset.java file:

package week2;

import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.StdIn;

public class Subset {

    public static void main(String[] args) {
        int k = Integer.parseInt(args[0]);
        RandomizedQueue<String> randQueue = new RandomizedQueue<String>();
        while (!StdIn.isEmpty()) {
            randQueue.enqueue(StdIn.readString());
        }

        for (int i = 0; i < k; i++) {
            StdOut.println(randQueue.dequeue());
        }
    }

}

There is also a RandomizedQueue.java in the same folder. However, when I run javac-algs4 Subset.java in the terminal, I get the following error:

Subset.java:10: error: cannot find symbol
        RandomizedQueue<String> randQueue = new RandomizedQueue<String>();
        ^
  symbol:   class RandomizedQueue
  location: class Subset
Subset.java:10: error: cannot find symbol
        RandomizedQueue<String> randQueue = new RandomizedQueue<String>();
                                            ^
  symbol:   class RandomizedQueue
  location: class Subset
2 errors

(Please excuse me, I am brand new to Java.)

Louis Cruz
  • 1,703
  • 2
  • 15
  • 20
  • 1
    Try using an IDE. It'll point out the error before you attempt to manually compile the code – OneCricketeer Dec 12 '16 at 03:54
  • 1
    I am using Eclipse as well. It doesn't show an error before compilation, but when I send it in for grading (through coursera) I'm getting that error. – Louis Cruz Dec 12 '16 at 03:54
  • I don't know what `javac-algs4` does, but you have to compile all classes together. This is called building the classpath – OneCricketeer Dec 12 '16 at 03:56
  • @cricket_007 my apologies – Mritunjay Dec 12 '16 at 03:56
  • It seems like `javac-algs4` just compiles with the given `algs4.jar` library. When I run with just `javac` I just get errors that the `StdIn` and `StdOut` methods don't exist. – Louis Cruz Dec 12 '16 at 03:58
  • If we read the duplicate, you'll see "If you have never compiled Bar and you run javac Foo.java, you are liable to find that the compiler can't find the symbol Bar", and that's what's happening here – OneCricketeer Dec 12 '16 at 03:58
  • Oh, if you are exporting a jar file, then you'll need to check all related classes, and that might not include `edu.princeton.cs.algs4`, but I'm sure the coursera course probably gives better instructions – OneCricketeer Dec 12 '16 at 04:00
  • Unfortunately I can't find any real instructions. Also, I've read through the proposed duplicate several times and really don't see what I need to do to get this to work. – Louis Cruz Dec 12 '16 at 04:17

0 Answers0