Scanner cannot be resolved to a type

23,360

The Scanner class is new in Java 5. I do not know what Hardy's default Java environment is, but it is not Sun's and therefore may be outdated.

I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.

Share:
23,360
Austin
Author by

Austin

Updated on June 18, 2021

Comments

  • Austin
    Austin almost 3 years

    I just installed Ubuntu 8.04 and I'm taking a course in Java so I figured why not install a IDE while I am installing it. So I pick my IDE of choice, Eclipse, and I make a very simple program, Hello World, to make sure everything is running smoothly. When I go to use Scanner for user input I get a very odd error:

    My code:

    import java.util.Scanner;

    class test { public static void main (String [] args) { Scanner sc = new Scanner(System.in); System.out.println("hi"); } }

    The output:

    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
        Scanner cannot be resolved to a type
        Scanner cannot be resolved to a type
    
       at test.main(test.java:5)
    
  • Sven Eberth
    Sven Eberth almost 3 years
    Welcome to StackOverflow. While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.