aspose file tools*
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""cannot resolve symbol" error when compiling..." Watch ""cannot resolve symbol" error when compiling..." New topic
Author

"cannot resolve symbol" error when compiling...

Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
Hello,

So, in the middle of one of my homework assignments, I start getting this error in relation to the scanner class. I thought it might be an error in my code, but I couldn't find any. So I made a completely new project that would simply test out using the scanner class. No dice.

I don't know what I'm doing wrong here. I've looked through the API in relation to the Scanner class and everything seems to check okay.



When this runs, the command prompt shows:

C:\java\projects>javac ScanDemo1.java
ScanDemo1.java:1: cannot resolve symbol
symbol : class Scanner
location: package util
import java.util.Scanner;
^
ScanDemo1.java:7: cannot resolve symbol
symbol : class Scanner
location: class ScanDemo1
Scanner sc = new Scanner(System.in);
^
ScanDemo1.java:7: cannot resolve symbol
symbol : class Scanner
location: class ScanDemo1
Scanner sc = new Scanner(System.in);
^
3 errors

C:\java\projects>

I don't really understand where the compiler is having trouble. Any suggestions?

NOTE: When posting this, I realized the arrows wouldn't point to what I was seeing, and would instead go to the beginning of the line. I made the letters that the arrows were pointing at BOLD so that you'd see what I was seeing. Except, on the third arrow, I tried making the equals sign (=) bold, but that didn't seem to do much. So, on the third error, the arrow is pointing at the equals sign.

Thanks a ton!


Carpe diem, because every day is worth living to its fullest.
Jiken Jarecha
Greenhorn

Joined: Feb 17, 2009
Posts: 9
http://www.coderanch.com/t/431655/Java-General-beginner/java/Symbol-Class-error-no-package

This may help
Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
I'm sorry. I don't fully understand what went on during that post.

Do you think my classpath might be incorrect? Everything else java related seems to run flawlessly until I try out the scanner class. Is it possible that when I say:

import java.util.Scanner;

...it is unable to find that file? If so, how would I go about fixing that?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1760
    
    7

What JDK version are you using?


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38348
    
  23
I don't think the other thread quoted actually helps. Jelle Klap is probably right; those of us who have been using Scanner for 4 years forget it wasn't available in jdk1.4.
Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
JDK v1.4.2

For some reason, everything compiles fine on my computer except when I try to use Scanners. That's not really saying much since "import java.util.Scanner" is the only import I've ever tried.

I tried the same code at my school and it compiled and ran. So I've narrowed the problem down to my computer.

Should I simply uninstall and reinstall the JDK and JRE? They're both in completely separate parts of my computer. JDK is in "C:\java" and JRE is in "C:\Program Files (x86)\Java\jre6" (also, in that same Program Files (x86)\Java folder there's a j2re1.4.2_19 and jre1.6.0_05 folder. Don't know if that changes anything)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4174
    
  21

Nick Garcia wrote:JDK v1.4.2


Well there's your problem. Scanner was added in Java 1.5.


Steve
Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
Huh...wonder how that happened. I downloaded it about two weeks ago. lol Must have clicked the wrong one! Thanks a ton! I'll go grab an update.
Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
When I go to java.sun.com I look for the latest JDK and it says jdk-6u12-windows-x64-p.exe is the latest, which is what I downloaded. Is that different from the v1.4.2? If so, how to do get myself up to 1.5?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18710
    
  40

Nick Garcia wrote:When I go to java.sun.com I look for the latest JDK and it says jdk-6u12-windows-x64-p.exe is the latest, which is what I downloaded. Is that different from the v1.4.2? If so, how to do get myself up to 1.5?


The version you downloaded is Java 6 (update 12). And yes it is different from 1.4.2. In order of release... Java 1.4.2 --> Java 5 --> Java 6. The Scanner class was added at Java 5. So, the version you download supports the Scanner class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4174
    
  21

jdk-6 is Java 6, the latest release. Java 1.5 is the previous version, and Java 1.4 is 2 versions ago (and if I recall near its 'end of life'). So JDK-6 is the latest and the one you should use.
Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
Hmm...for some reason, when I open up "README.txt" in the jdk folder, it says 1.4.2, yet the one I downloaded was definitely JDK 6u12.

And since I have 6u12, that kind of puts me back into a problem when calling java.util.Scanner. Hmm...this is mind-boggling.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18710
    
  40

Nick Garcia wrote:Hmm...for some reason, when I open up "README.txt" in the jdk folder, it says 1.4.2, yet the one I downloaded was definitely JDK 6u12.

And since I have 6u12, that kind of puts me back into a problem when calling java.util.Scanner. Hmm...this is mind-boggling.


To determine the version of Java, use.... java -version

Henry
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

Henry Wong wrote:
Nick Garcia wrote:Hmm...for some reason, when I open up "README.txt" in the jdk folder, it says 1.4.2, yet the one I downloaded was definitely JDK 6u12.

And since I have 6u12, that kind of puts me back into a problem when calling java.util.Scanner. Hmm...this is mind-boggling.


To determine the version of Java, use.... java -version

Henry


Looks like you might have two versions of JDK installed on your computer.
To make sure whats happening,

1. As Henry says do a java -version at you command prompt.
It will display the java version that is being used.


2. Type 'path' on you command prompt.
This will get us in which folder the javac is being executed from.

3. What is the location in which the JDK is installed? Does it have the word jdk1.6.xxxx in it? Can you type in the path of where java is installed on your computer?


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Nick Garcia
Greenhorn

Joined: Dec 30, 2008
Posts: 15
My apologies for the delayed response.



This is what I see when those two commands are typed. From what I see, my path is set wrong. I'm considering uninstalling almost everything java and just starting back fresh. I believe when prompted during the installation of JDK, I changed the default path to C:\java, but I'm not sure. Also, I cannot find a folder on my computer starting with jdk1.6*****. I think I somehow messed up the installation. After uninstalling and reinstalling it, I will post here with the results. I'm sure that will fix all of the issues I'm experiencing.

Thank you all for your excellent suggestions! I didn't even think about checking the path.

-Nick
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

Nick,

Actually your path as well as java version look pretty much correct. Yes you are right you probably changed you installation folder to C:\Java while doing the installation which is very much ok.

Instead of re-installing everything (I hope you have not already done that!) there is one last thing that you need to check.
This is the classpath variable.

To check what your classpath is set to type (at command prompt)



You should have C:\java\bin.

If not this is what you need to do,

1. Right Click on My computer and select properties.
2. Click on advance tab.
3. Click on Environment variables.
4. Define a new system Variable called classpath and set its value to C:\java\bin.

Alternately you could try running your program using this command line,



Hope this helps!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38348
    
  23
By "classpath", surely you mean "path"? The two are completely different. You need a PATH to compile anything, but you probably don't need a CLASSPATH at the beginner's stage at all. If you are in the correct directory, you only need to quote a classpath when executing external or downloaded .jars.
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

Campbell Ritchie wrote:By "classpath", surely you mean "path"? The two are completely different. You need a PATH to compile anything, but you probably don't need a CLASSPATH at the beginner's stage at all. If you are in the correct directory, you only need to quote a classpath when executing external or downloaded .jars.


Nopes by classpath I did mean classpath.
Yes you are right beginners should not bother about classpath but there is nothing stopping the classpath from bothering beginners . (loads of problems in my life due to classpath!!)

Surely there is nothing wrong with Nick's path otherwise the compilation process would not start. Clearly java -version gives the correct answer. That leaves us with just one possibility the dreaded classpath.

And I think looking at Campbell Ritchie's ( ) explanation in this post would hold the true answer (Sorry, just felt a little cheeky, But I do hope I got all my concepts right. Someone Confirm ?)

My Guess...
Nick mention that his java code seem to compile and run fine until he started trying out the scanner class. So if I were to pinpoint the problem I'd say his classpath is set to the bin folder of JDK 1.4 creating the conflict!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38348
    
  23
Sorry about the confusion. I might possibly have been right in the other post (it does happen, by random association ) in which case it is might be worth trying

javac cp . MyClass.java

The cp . includes the "current directory" in the classpath. If you don't set a classpath at all, then the javac tool uses "current directory" by default. If you have set a classpath the javac tool (or the java tool) only looks for classes in the classpath you have set. In which case adding a . for current directory to the system classpath might help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "cannot resolve symbol" error when compiling...