PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Oct-13 11:19 am
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 |
actions · 2004-Oct-13 11:19 am · (locked) |
|
try makeing the import line just like this: |
actions · 2004-Oct-13 1:10 pm · (locked) |
GILXA1226 |
to PToN
upon further inspection of your code where are you declaring the variable scan from this line? fahrenheitTemp = scan.nextDouble();
|
actions · 2004-Oct-13 1:53 pm · (locked) |
PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Oct-14 3:17 pm
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...? |
actions · 2004-Oct-14 3:17 pm · (locked) |
|
Can you post your updated code? |
actions · 2004-Oct-14 4:14 pm · (locked) |
javaManThe Dude abides. MVM join:2002-07-15 San Luis Obispo, CA 4 edits |
to PToN
You should create an object, something like:
Scanner scan = new Scanner(System.in); fahrenheitTemp = scan.nextDouble(); |
actions · 2004-Oct-14 6:11 pm · (locked) |
PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Oct-14 7:15 pm
***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 |
actions · 2004-Oct-14 7:15 pm · (locked) |
javaManThe Dude abides. 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. |
actions · 2004-Oct-14 8:22 pm · (locked) |
PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Oct-14 9:42 pm
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 |
actions · 2004-Oct-14 9:42 pm · (locked) |
|
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. |
actions · 2004-Oct-14 10:10 pm · (locked) |
PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Oct-18 4:02 pm
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 |
actions · 2004-Oct-18 4:02 pm · (locked) |
|
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. |
actions · 2004-Oct-18 5:37 pm · (locked) |
PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Oct-18 5:56 pm
yes i am using 1.4.2.
I guess i ll up grade..
Thanks for testing it out.. |
actions · 2004-Oct-18 5:56 pm · (locked) |
javaManThe Dude abides. MVM join:2002-07-15 San Luis Obispo, CA |
to PToN
The scanner class is new to 1.5. You will need to download the current JDK. |
actions · 2004-Oct-18 5:57 pm · (locked) |
PToN Premium Member join:2001-10-04 Houston, TX |
PToN
Premium Member
2004-Nov-15 8:34 pm
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 |
actions · 2004-Nov-15 8:34 pm · (locked) |
stateq2control the code Premium Member join:2003-03-27 Jackson, MS |
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 |
actions · 2004-Dec-3 5:03 pm · (locked) |