aspose file tools*
The moose likes Beginning Java and the fly likes import java.util.Scanner issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "import java.util.Scanner issues" Watch "import java.util.Scanner issues" New topic
Author

import java.util.Scanner issues

Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Hello all, officially my second out of what I promise to be many posts.

I've been searching around online for other Java tutorials (now have a few good ones plus the Head First Java book) and came across java.util.Scanner in a practical exercise.

If I compile the code in an ide (which I know everyone hates for beginners) it compiles fine.

If I compile from the command line, using javac LoopingLock.java, I get compile errors stating..

LoopLock.java:1: cannot resolve symbol
symbol: class Scanner
location: package util
import java.util.Scanner;
^

And other various compile errors complaining about me trying to use Scanner.

Here is a bit of the code from my java file.


I'm not so sure it's an error in my code so much as perhaps an error in my system variables somewhere? But if that's the case, wouldn't the commands javac and java also not be working?

Any help would be appreciated so I can learn from the command line before going ezmode with Eclipse or Netbeans.

Thanks,

Nate


The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Nathan Leniz:
... I'm not so sure it's an error in my code so much as perhaps an error in my system variables somewhere? But if that's the case, wouldn't the commands javac and java also not be working? ...

Scanner was introduced with Java 1.5, so my guess is that your system PATH is pointing to a prior version (so the commands work, but not with new features).

You can type "javac -version" (without the quotes) to check the compiler version. You'll get a lengthy error message for not specifying a source file, but the version should display first...

What operating system are you running?
[ December 04, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
javac -version wasn't a valid command

I tried java -version and it printed this to the screen...

java version "1.5.0_09"

Followed by other information about Java.

Still just as stumped. I hate being a noob. I appreciate the fast reply.

Oh, Windows XP home.

Nate

[ December 04, 2006: Message edited by: Nathan Leniz ]
[ December 04, 2006: Message edited by: Nathan Leniz ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Since javac -version doesn't work, that means you're Java compiler is not 1.5.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Keith Lynn:
Since javac -version doesn't work, that means you're Java compiler is not 1.5.

Right, the "-version" flag for javac was added with 1.5. And yet the java version seems okay, and these tools should both be in the same directory.

What does your system PATH look like?

Also, if you have a system CLASSPATH set, what does that look like?

(For Windows XP, I think these are under Start > Settings > Control Panel > System > Advanced > Environment Variables.)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18978
    
  40

For eariler versions of the Java compiler, also try...

javac -J-version

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
I think it's possible that an updated JRE was placed on the machine when the OP installed a browser, but possibly the only JDK is 1.4 or 1.3.
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
javac -J-version shows java version "1.4.2_13"

my path is set to c:\j2sdk1.4.2_13\bin

and classpath is set to the same. One of my friends (who I can't get on googletalk atm) helped me set it up initially and told me to make them both the same, so perhaps it could have been bad advice?

Nathan
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The version of the JDK didn't include Scanner.

Did you ever download 1.5?
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
I thought I did, but perhaps I didn't. I'm downloading again.

Thanks for all the replies. I'll have to show my wife this thread, perhaps she'll cave and let me go on the Cattle Drive.

Nate
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
Upon further investigation, I found out the Java I thought I was installing but not seeing was going into a nice little folder in my Program Files. javac version is now 1.5.0_10 along with the java version.

I R dumb. Feel free to beat me. Thanks again everyone for your help.

Nathan
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

So the code compiles now, right?

I would also suggest removing the system CLASSPATH entirely. Until you get comfortable with how this works, it's likely to cause problems (especially since it probably does not include the current directory ".").
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
It does compile, yes.

And it runs.

And it took me a minute or two to figure out why I had to keep going
set CLASSPATH =

Then it finally dawned on me that I have to add every directory I plan on storing stuff in, so I went back and changed the classpath variable to include the real Java 1.5, as well as my projects folder.

my variables now look like

path = C:\Program Files\Java\jdk1.5.0_10\bin
classpath = C:\Program Files\java\jdk1.5.0_10\bin;C:\projects

Actually crashing through it full bore, reading the stuff here and reading the documentation from Sun helped me out quite a bit. I just wish they would have explained it in plain english, like "Make the variable name Classpath, then in the variable value type out the true path to your Java directory, put a semi-colon there, then type out the true path to whatever other directories you plan on storing your *.java and *.class files in"

Maybe not truly the right way, but it works. And yeah, it probably does say that, but us military folk ain't big on reading and ejukayshun.

Again, thanks for all the help. I'm sure more questions will follow.

Cheers,

Nate
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I would still recommend that you remove the CLASSPATH variable entirely. With earlier versions of Java, you needed to set this; but now Java is "smart" enough to find the basics without it, and having this set will likely cause problems later. If you do keep it, then at least add a dot (".") to indicate the current directory...

classpath = .;C:\Program Files\java\jdk1.5.0_10\bin;C:\projects
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
I'll heed the advice of those who know more than me. I've removed the classpath variable entirely and everything still works.

Ah, to make up for all these shenanigans, I shared (what I think is) a very funny story in the drivel and nonsense forum.

Again, thanks much.

Nate
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: import java.util.Scanner issues