site Search:


 
    All Forums Hot Topics Gallery






how-to block ads


 
Search Topic:
Uniqs:
569
Share Topic
Posting?
AuthorAll Replies


PToN

join:2001-10-04
Houston, TX

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
Premium,MVM
join:2000-12-29
London, OH

try makeing the import line just like this:

import java.util.*;

--
10010 Wheels on a Bigrig


GILXA1226
Premium,MVM
join:2000-12-29
London, OH

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

fahrenheitTemp = scan.nextDouble();

--
10010 Wheels on a Bigrig


PToN

join:2001-10-04
Houston, TX

reply to PToN
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
Premium,MVM
join:2000-12-29
London, OH

Can you post your updated code?
--
10010 Wheels on a Bigrig



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

4 edits

reply to PToN
You should create an object, something like:

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



PToN

join:2001-10-04
Houston, TX

reply to PToN

***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.
Premium,MVM
join:2002-07-15
San Luis Obispo, CA

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.
--
Woe unto them that call evil good, and good evil; that put darkness for light, and light for darkness. . . Isa. 5:20



PToN

join:2001-10-04
Houston, TX

reply to PToN
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
Premium,MVM
join:2000-12-29
London, OH

reply 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.
--
10010 Wheels on a Bigrig


PToN

join:2001-10-04
Houston, TX

reply to PToN

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
Premium,MVM
join:2000-12-29
London, OH

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.
--
10010 Wheels on a Bigrig



PToN

join:2001-10-04
Houston, TX

reply to PToN
yes i am using 1.4.2.

I guess i ll up grade..

Thanks for testing it out..



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

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



PToN

join:2001-10-04
Houston, TX

reply to PToN
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
join:2003-03-27
Jackson, MS

reply 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


Sunday, 27-May 11:27:33 Terms of Use & Privacy | feedback | contact | Hosting by nac.net - DSL,Hosting & Co-lo
over 12.5 years online © 1999-2012 dslreports.com.
Most commented news this week
Hot Topics