4

I am using Intellij IDEA.

Here is my code:

public static void main(String[] args) {
        java.util.Scanner scanner = new java.util.Scanner(System.in);

        int a = scanner.nextInt();
        System.out.println(a);
}

The problem is that when I run it, it works. But, Intellij cannot find Scanner class. It is underlining with red color.

How to fix this?

Ingo Bürk
  • 19,263
  • 6
  • 66
  • 100
Jonik
  • 141
  • 3
  • 14
  • 1
    Hovering over the red-line, I get Cannot resolve symbol. And it is not only for Scanner class. System.out.println cannot be found too. The strage part is that it is compiling and running fine – Jonik Nov 02 '14 at 19:08
  • If you can successfully compile it and run it then it may be some false-positive code analysis error ... IntelliJ gives me those from time to time (possibly a bug in the IDE?). When I restart IntelliJ it usually disappears. This also happens when you don't have project SDK defined, but since you can compile and run it that's probably not the case. – Bohuslav Burghardt Nov 02 '14 at 19:09
  • 1
    I restarted the IDE, not helping. I also think that it is a bug in IDE or something – Jonik Nov 02 '14 at 19:11
  • 3
    Try to clear IntelliJ cache: `File | Invalidate Caches / Restart..` – Anton Dozortsev Nov 02 '14 at 20:22

2 Answers2

3

First you should import the Scanner like this:

import java.util.Scanner;// in the top!

and then try this:

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    System.out.println(a);
}
sasuri
  • 972
  • 3
  • 11
  • 26
-1

Right click on code editor window and click on run.