Java – Scanner cannot be resolved to a type

eclipsejavaUbuntu

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)

Best Answer

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.

Related Topic