This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
You need to run this program from the command prompt or terminal. Netbeans doesn't count as a console apparently.
I don't know what kind of software you've got but this works for me on a Mac with the bash terminal java -jar <jar name>
you also might want to take out the firstName variable initialization because it doesn't have a corresponding prompt for the user and it seems repetitive.
you also might want to take out the firstName variable initialization because it doesn't have a corresponding prompt for the user and it seems repetitive.
David Hulse wrote:I don't know what kind of software you've got but this works for me on a Mac with the bash terminal java -jar <jar name>
Well I am using Eclipse 3.6.2, however, I tried it in command prompt, and, it seems like the for ... each loop is not working well, since, I only get the last character of the password returned:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Jon>cd My Documents
C:\Documents and Settings\Jon\My Documents>cd Working Folder
C:\Documents and Settings\Jon\My Documents\Working Folder>cd JavaDev
C:\Documents and Settings\Jon\My Documents\Working Folder\JavaDev>cd myCode Snip
pets
C:\Documents and Settings\Jon\My Documents\Working Folder\JavaDev\myCode Snippet
s>prompt $g
>dir
Volume in drive C has no label.
Volume Serial Number is D80F-8634
Directory of C:\Documents and Settings\Jon\My Documents\Working Folder\JavaDev\
myCode Snippets
>java TestThree
What's your name?Jon C.
C.
How old are you?31
Hello, Jon C., next year you will be 32 years old.Enter a password:
[Password :]
Password keyed in: s
Excuse the inflammatory terms, btw, it was only intended as a study program I'm using Win XP SP3.
When I try this within Eclipse I get the following:
Enter a password:
Exception in thread "main" java.lang.NullPointerException at TestThree.main(TestThree.java:21) - line 21 refers to
David Hulse wrote:You need to run this program from the command prompt or terminal. Netbeans doesn't count as a console apparently.
Jon, this also applies for Eclipse, and probably every other IDE. That's why you get a NullPointerException - System.console() returns null.
You get the NullPointerException before the "Enter a password" prompt because the NullPointerException is sent to System.err and the prompt to System.out, and Eclipse is quite bad at interweaving these two as you expect.
Jon Camilleri wrote:
That's too bad, I thought Eclipse and Netbeans were fairly reliable.
They are reliable.
From the Console API:
If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and
...
If this virtual machine has a console then it is represented by a unique instance of this class which can be obtained by invoking the System.console() method.
If no console device is available then an invocation of that method will return null.
OCUP UML fundamental
ITIL foundation
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.