Discussion:
System.console() issue with Mac OS X
j***@gmail.com
2014-10-10 23:39:39 UTC
Permalink
Hi,

I am running NetBeans 8.0.1 on a Mac running Mac OS X. I am trying to
set up a program to read user entry from the keyboard. I use the
following code:

----------------------------------------------

Console con;

...

try {
con = System.console();
if (con != null) {
selection = con.readLine();
}
} catch (Exception ex) {

}

----------------------------------------------

The problem is, even after the step con = System.console();, the
debugger says that con is null. Do I need to set up something on the
Mac itself, or are there problems with the code?


Thanks,

Jim
Simon Roberts
2014-10-11 06:10:09 UTC
Permalink
Console is weird. Never seems to work in any IDE

use something like this:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();

That should work reliably for you.
Post by j***@gmail.com
Hi,
I am running NetBeans 8.0.1 on a Mac running Mac OS X. I am trying to
set up a program to read user entry from the keyboard. I use the
----------------------------------------------
Console con;
...
try {
con = System.console();
if (con != null) {
selection = con.readLine();
}
} catch (Exception ex) {
}
----------------------------------------------
The problem is, even after the step con = System.console();, the
debugger says that con is null. Do I need to set up something on the
Mac itself, or are there problems with the code?
Thanks,
Jim
--
Simon Roberts
Certified Professional Photographer
http://dancingcloudphotography.com
(303) 249 3613
geertjan wielenga
2014-10-11 08:35:37 UTC
Permalink


Gj
Post by Simon Roberts
Console is weird. Never seems to work in any IDE
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
That should work reliably for you.
Hi,
I am running NetBeans 8.0.1 on a Mac running Mac OS X. I am trying to
set up a program to read user entry from the keyboard. I use the
----------------------------------------------
Console con;
...
try {
con = System.console();
if (con != null) {
selection = con.readLine();
}
} catch (Exception ex) {
}
----------------------------------------------
The problem is, even after the step con = System.console();, the
debugger says that con is null. Do I need to set up something on the
Mac itself, or are there problems with the code?
Thanks,
Jim
--
Simon Roberts
Certified Professional Photographer
http://dancingcloudphotography.com
(303) 249 3613
Simon Roberts
2014-10-11 14:05:19 UTC
Permalink
Oh! Nice, that'll be useful in many ways :)

Thanks Geertjan

Cheers,
Simon

On Sat, Oct 11, 2014 at 2:35 AM, geertjan wielenga <
Post by geertjan wielenga
http://youtu.be/zyesu4fRGag
Gj
Console is weird. Never seems to work in any IDE
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
That should work reliably for you.
Post by j***@gmail.com
Hi,
I am running NetBeans 8.0.1 on a Mac running Mac OS X. I am trying to
set up a program to read user entry from the keyboard. I use the
----------------------------------------------
Console con;
...
try {
con = System.console();
if (con != null) {
selection = con.readLine();
}
} catch (Exception ex) {
}
----------------------------------------------
The problem is, even after the step con = System.console();, the
debugger says that con is null. Do I need to set up something on the
Mac itself, or are there problems with the code?
Thanks,
Jim
--
Simon Roberts
Certified Professional Photographer
http://dancingcloudphotography.com
(303) 249 3613
--
Simon Roberts
Certified Professional Photographer
http://dancingcloudphotography.com
(303) 249 3613
Continue reading on narkive:
Loading...