You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by "Christopher C. Lanz" <la...@potsdam.edu.INVALID> on 2020/12/16 18:11:31 UTC

print before take Scanner input not working

Hello,

For many years, and both with NetBeans and with just a terminal, I have used methods like this, to prompt the user to enter (say) an integer:

public static int inkeyInteger( String message ){

    System.out.print( message );
    Scanner console = new Scanner(System.in);
    return console.nextInt();

}

Now in NetBeans 12, this code fails - the message is not printed until after the user supplies data to the Scanner.

I have tried all the possible orderings of these 3 lines of code, and passing the Scanner, etc. etc. I have searched StackOverflow.

It can be worked around if I print the message before calling a method containing the scanner definition and next() call. This will require changing hundreds of method calls throughout a large program.

Is there a workaround or patch etc.?


Chris Lanz

Department of Computer Science

340 Dunn Hall, SUNY Potsdam

lanzcc@potsdam.edu

315 267 2407

315 268 1547


Nature and nature's laws lay hid in night:
God said, Let Newton be! and all was light. (Pope)

It did not last: the Devil howling "Ho!
Let Einstein be!" restored the status quo. (Squire)


Re: print before take Scanner input not working

Posted by Peter <to...@gmail.com>.
This was introduced sometime after Maven 3.3.9 (after Netbeans 11.1). Running Netbeans 12.1 with Maven from Netbeans 11.1 is a work around.

On 2020/12/16 18:11:31, "Christopher C. Lanz" <la...@potsdam.edu.INVALID> wrote: 
> Hello,
> 
> For many years, and both with NetBeans and with just a terminal, I have used methods like this, to prompt the user to enter (say) an integer:
> 
> public static int inkeyInteger( String message ){
> 
>     System.out.print( message );
>     Scanner console = new Scanner(System.in);
>     return console.nextInt();
> 
> }
> 
> Now in NetBeans 12, this code fails - the message is not printed until after the user supplies data to the Scanner.
> 
> I have tried all the possible orderings of these 3 lines of code, and passing the Scanner, etc. etc. I have searched StackOverflow.
> 
> It can be worked around if I print the message before calling a method containing the scanner definition and next() call. This will require changing hundreds of method calls throughout a large program.
> 
> Is there a workaround or patch etc.?
> 
> 
> Chris Lanz
> 
> Department of Computer Science
> 
> 340 Dunn Hall, SUNY Potsdam
> 
> lanzcc@potsdam.edu
> 
> 315 267 2407
> 
> 315 268 1547
> 
> 
> Nature and nature's laws lay hid in night:
> God said, Let Newton be! and all was light. (Pope)
> 
> It did not last: the Devil howling "Ho!
> Let Einstein be!" restored the status quo. (Squire)
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@netbeans.apache.org
For additional commands, e-mail: users-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: print before take Scanner input not working

Posted by Laszlo Kishalmi <la...@gmail.com>.
The build tool is important here.

I think you are experiencing: NETBEANS-4617

The fix for that is in 12.2: https://github.com/apache/netbeans/pull/2270

It is marked to be backported to NetBeans 12.0-u2


On 12/16/20 10:11 AM, Christopher C. Lanz wrote:
> Hello,
>
> For many years, and both with NetBeans and with just a terminal, I 
> have used methods like this, to prompt the user to enter (say) an integer:
>
> public static int inkeyInteger( String message ){
>
>     System.out.print( message );
>     Scanner console = new Scanner(System.in);
>     return console.nextInt();
>
> }
>
> Now in NetBeans 12, this code fails - the message is not printed until 
> after the user supplies data to the Scanner.
>
> I have tried all the possible orderings of these 3 lines of code, and 
> passing the Scanner, etc. etc. I have searched StackOverflow.
>
> It can be worked around if I print the message before calling a method 
> containing the scanner definition and next() call. This will require 
> changing hundreds of method calls throughout a large program.
>
> Is there a workaround or patch etc.?
>
> Chris Lanz
>
> Department of Computer Science
>
> 340 Dunn Hall, SUNY Potsdam
>
> lanzcc@potsdam.edu
>
> 315 267 2407
>
> 315 268 1547
>
>
> Nature and nature's laws lay hid in night:
> God said, /Let Newton be!/ and all was light. (Pope)
>
> It did not last: the Devil howling "Ho!
> Let Einstein be!" restored the status quo. (Squire)
>
>