dslreports logo
 
    All Forums Hot Topics Gallery
spc
Search similar:


uniqs
4503

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

Cant find scanner class...?

Hello, i am taking this class on Java and when i try to compile any of my projects i get a message that the scanner class cant be found. I have tired Jgrasp, NetBeans, Kdevelop and others and it still wont work which makes me belive that there is something that i havent installed...

The actual error says: " cant find symbol | symbol: class Scanner | location: package java.util"

Any ideas...?

import java.util.Scanner;

public class TempConverter
{
public static void main (String[] args)
{
final int BASE = 32;
final double COVERSION_FACTOR = 5.0 / 9.0;

double fahrenheitTemp, celsiusTemp;

System.out.print ("Please enter Fahrentheit Temperature: ");

fahrenheitTemp = scan.nextDouble();

celsiusTemp = fahrenheitTemp - BASE * COVERSION_FACTOR;

System.out.println ("Celsius Temperature: " + celsiusTemp);
System.out.println ("Farenheit Equivalent: " + fahrenheitTemp);
}
}

thanks

GILXA1226
MVM
join:2000-12-29
Dayton, OH

GILXA1226

MVM

try makeing the import line just like this:

import java.util.*;
GILXA1226

GILXA1226 to PToN

MVM

to PToN
upon further inspection of your code where are you declaring the variable scan from this line?

fahrenheitTemp = scan.nextDouble();

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

I did what you told me and the import line doesnt give me an error, now all i get is that Scanner is not found... I also fixed the scan.nextDouble() part..

any ideas...?

GILXA1226
MVM
join:2000-12-29
Dayton, OH

GILXA1226

MVM

Can you post your updated code?

javaMan
The Dude abides.
MVM
join:2002-07-15
San Luis Obispo, CA

4 edits

javaMan to PToN

MVM

to PToN
You should create an object, something like:

Scanner scan = new Scanner(System.in);
fahrenheitTemp = scan.nextDouble();

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

***import java.util.*;***

public class TempConverter
{
public static void main (String[] args)
{
final int BASE = 32;
final double COVERSION_FACTOR = 5.0 / 9.0;

double fahrenheitTemp, celsiusTemp;

*** Scanner scan = scanner.create(System.in);***

System.out.print ("Please enter Fahrentheit Temperature: ");

***fahrenheitTemp = scan.nextDouble();***

celsiusTemp = fahrenheitTemp - BASE * COVERSION_FACTOR;

System.out.println ("Celsius Temperature: " + celsiusTemp);
System.out.println ("Farenheit Equivalent: " + fahrenheitTemp);
}
}


Lines with *** **** where the ones modified

javaMan
The Dude abides.
MVM
join:2002-07-15
San Luis Obispo, CA

javaMan

MVM

Change this:
Scanner scan = scanner.create(System.in);
to this:
Scanner scan = new Scanner(System.in);

As far I am aware Scanner has no create method.

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

I havent tried it yet since i am not home yet, but the system.create(system.in) was taken as shown on my book... It might be a typo.. I think that i ll find out when i get home and try with the "new"

Thanks

GILXA1226
MVM
join:2000-12-29
Dayton, OH

GILXA1226 to javaMan

MVM

to javaMan
said by javaMan:
Change this:
Scanner scan = scanner.create(System.in);
to this:
Scanner scan = new Scanner(System.in);

As far I am aware Scanner has no create method.

Yeah, that is what it needs to be. It's been awhile since I've done any command line processing... might be time for some refresher stuff.

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

import java.util.*;

public class TempConverter
{
public static void main (String[] args)
{
final int BASE = 32;
final double COVERSION_FACTOR = 5.0 / 9.0;

double fahrenheitTemp, celsiusTemp;

Scanner scan = new Scanner(System.in);

System.out.print ("Please enter Fahrentheit Temperature: ");

fahrenheitTemp = scan.nextDouble();

celsiusTemp = fahrenheitTemp - BASE * COVERSION_FACTOR;

System.out.println ("Celsius Temperature: " + celsiusTemp);
System.out.println ("Farenheit Equivalent: " + fahrenheitTemp);
}
}

When i compile that it comes up with:
Compiling 1 source file to C:\Documents and Settings\Panchin\My Documents\Programming\Assi
*gment-3\build\classes
C:\Documents and Settings\Panchin\My Documents\Programming\Assigment-3\src\TempConverter.j
*ava:15: cannot resolve symbol
symbol : class Scanner
location: class TempConverter
Scanner scan = new Scanner(System.in);
C:\Documents and Settings\Panchin\My Documents\Programming\Assigment-3\src\TempConverter.j
*ava:15: cannot resolve symbol
symbol : class Scanner
location: class TempConverter
Scanner scan = new Scanner(System.in);
2 errors

(*) WARNING 3 long line(s) split

I really dont know if it is a problem with the code or with the compiler. I think it might be the compiler, but not sure... Any other ideas....?

Thanks

GILXA1226
MVM
join:2000-12-29
Dayton, OH

GILXA1226

MVM

What Java version are you using? With 1.5 it works, with 1.4.2 it doesn't... must be something new with version 1.5.

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

yes i am using 1.4.2.

I guess i ll up grade..

Thanks for testing it out..

javaMan
The Dude abides.
MVM
join:2002-07-15
San Luis Obispo, CA

javaMan to PToN

MVM

to PToN
The scanner class is new to 1.5. You will need to download the current JDK.

PToN
Premium Member
join:2001-10-04
Houston, TX

PToN

Premium Member

Guys i am still having problems with this.. I can compile and it does it with no problems, but it just wont run the little application. I installed the latest release of Netbenas which comes with the latest jdk (1.5) and it still wont work... It actually puts a red line under this:
Scanner scan = new Scanner(System.in);

The semester is almost over and i need to find a solution to the compiling and running so i can submit my homework..

Any ideas..?

Thanks

stateq2
control the code
Premium Member
join:2003-03-27
Jackson, MS

stateq2 to PToN

Premium Member

to PToN
yep...I'm taking a java class too, and at the beginning of the year, I kept getting those errors, because they didn't update the java version on the ssh server that we were doing our work on