Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Java getting error: Scanner cannot be resolved or is not a type

Status
Not open for further replies.

Enea

Technical User
Feb 23, 2005
90
0
0
US
New to Java. Following exercise #1 of a Java book.

Code is the following:

import java.util.*;

public class FirstProject
{
public static void main(String[] args)
{
System.out.println("Hello out there.");
System.out.println("I will add two numbers for you.");
System.out.println("Enter two whole numbers on a line:");

int n1, n2;

Scanner keyboard = new Scanner(System.in);
n1 = keyboard.nextInt( );
n2 = keyboard.nextInt( );

System.out.println("The sum of those two numbers is");
System.out.println(n1 + n2);
}
}


Error is:
Scanner cannot be resolved or is not a type
The import java.util is never used

Today I went to the following link:


and downloaded jdk-1_5_0_06-windows-i586-p-iftw.exe
I installed it but I am still getting the same error.

I am using Eclipse.

What do I need to do to solve the problem?

Thank you,

Ra..
 
Are you sure you are running JDK 1.5 / 5.0 ?
What does the command "java -version" give you ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
please do not cross-post in the future (J2EE forum).

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sedj: How do I find out what is the java version I am using?

(sorry about the double posting..after my first post I realized I posted in the incorrect forum)
 
I am not sure when I am suppose to type java-version to get the answer. I entered in Dos
c:\java-version
It gives: non recognized command

On my explorer browser I see:

Java Plug-in 1.5.0_06
Using JRE version 1.5.0_06 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Enea



 
You are missing a space.
In the 'dos' command prompt, type :

java -version

Try a cut'n'paste on the above command perhaps if you cannot get it to work.

BTW, I have successfully compiled and run (using JDK 1.5 ) the code you posted above, so it is not that the code is incorrect.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
BTW, I see you are using eclipse.
I always recommend that noobies use a simple text editor (on Windoze, I would use textpad, or notepad - NOT MS Word or Wordpad because they are not pure text editors).

And also, use the command line compiler and interpreter - using Eclipse will just hide from you what is actually going on when compiling code - and will result in noobies not even knowing the basics, ie what version of java they are actually running.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
java version "1.5.0_06"
 
Weird. Maybe Eclipse is using an internal non system, wide compiler< 1.5.

Take my advice above, and compile it on the console, and forget about fancy IDE's until you become more confident in what you are doing.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thank you for your help sedj. I just restarted my machine and the code is working fine this time.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top