• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"cannot resolve symbol" error when compiling...

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://coderanch.com/t/431655/Java-General-beginner/java/Symbol-Class-error-no-package

This may help
 
Nick Garcia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What JDK version are you using?
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Garcia wrote:JDK v1.4.2



Well there's your problem. Scanner was added in Java 1.5.
 
Nick Garcia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Nick Garcia
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic