1
votes

I got an error while trying to run my program from the command line.

My source code is:

public class Split {
    public static void main(String[] args) {
        String name = args[0];               // base file name
        int n = Integer.parseInt(args[1]);   // number of fields
        String delimiter = args[2];          // delimiter (comma)

        // create one output stream for each of the N fields
        Out[] out = new Out[n];
        for (int i = 0; i < n; i++) {
            out[i] = new Out(name + i);
        }

        // read in the input and divide by field
        In in = new In(name + ".csv");
        while (in.hasNextLine()) {
            String line = in.readLine();
            String[] fields = line.split(delimiter);
            for (int i = 0; i < n; i++) {
               out[i].println(fields[i]);
            }
        }
    }
}

The error I got:

C:\Users\zunayeed\Desktop\jav>javac Split.java Split.java:8: error: cannot find symbol Out[] out = new Out[n]; ^ symbol: class Out location: class Split Split.java:8: error: cannot find symbol Out[] out = new Out[n]; ^ symbol: class Out location: class Split Split.java:10: error: cannot find symbol out[i] = new Out(name + i); ^ symbol: class Out location: class Split Split.java:14: error: cannot find symbol In in = new In(name + ".csv"); ^ symbol: class In location: class Split Split.java:14: error: cannot find symbol In in = new In(name + ".csv"); ^ symbol: class In location: class Split 5 errors

Can anyone suggest how I can fix this error?

1

1 Answers

1
votes

According to your code and the error message, the reason you are getting the error is because the compiler can not find the 'In' class and the 'Out' class.

When you are compiling your program, you are just compiling the 'Split.java' file. In order to compile the other class files that Split.java requires, you must explicitly tell the compiler to compile those other classes as well. If they are located in the same folder as Split.java, then all you have to do to compile them is to run this in the command line:

javac In.java Out.java Split.java