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
C:\Documents and Settings\Jon\My Documents\Working Folder\JavaDev\myCode Snippet
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\
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.