Search code examples
javaintellij-idea

How to solve "Cannot resolve symbol" in IntelliJ IDEA?


I am learn Algorithms, 4th Edition with IntelliJ IDEA, however, I encouted a issue that the IDEA told me "Cannot resolve symbol 'StdIn' and 'StdOut'".

Pic: [Cannot resolve symbol "StdIn"](http: //i.imgur.com/ZRD6o53.jpg)

My project structure is correct and I set stdlib.jar as one of the dependencies, where there are StdIn and StdOut. Even I clicked "Invaildate caches and restart" the issue remains.

http://i.imgur.com/nVyoWP8.jpg

http://i.imgur.com/GvEwJtn.jpg

You may learn the details of stdlib.jar from here and Average.java

public class Average { 

   // this class should not be instantiated
   private Average() { }

    /**
     * Reads in a sequence of real numbers from standard input and prints
     * out their average to standard output.
     */
    public static void main(String[] args) { 
        int count = 0;       // number input values
        double sum = 0.0;    // sum of input values

        // read data and compute statistics
        while (!StdIn.isEmpty()) {
            double value = StdIn.readDouble();
            sum += value;
            count++;
        }

        // compute the average
        double average = sum / count;

        // print results
        StdOut.println("Average is " + average);
    }
}

Solution

  • This happens because the stdlib.jar does not define package structure for its classes :(

    Try creating your class on default package and that should work.