This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 50773 - Console does not accept input.
Summary: Console does not accept input.
Status: CLOSED DUPLICATE of bug 47708
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 4.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: issues@platform
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-23 18:50 UTC by tmanningtx
Modified: 2008-12-22 19:26 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description tmanningtx 2004-10-23 18:50:01 UTC
I am new to JAVA and have been running some 
sample exercises in NetBeans.  One of the 
exercises accepts input from the console.  In 
WASD at work, I copy the code in and it works as 
expected, in NetBeans 4.0 the first question 
appears on the console and the code immediately 
jumps to the evaluation which errors on a null 
value. There is no wait for a user entry. Is 
this an imcompatibility with the new JDK 1.5 or 
an issue with the NetBeans releaase.

The code looks like this:

System.out.println("How many nickels do you 
have?");
      String input = console.readLine();
      int count = Integer.parseInt(input);
      myPurse.addNickels(count);

It jumps straight into the Integer.parseInt line 
without waiting for input.  The complete code is 
available as an exercise under Chapter 3 at:

http://www.horstmann.com/ccj.html

It is a zip file entitled BigJava under the 
heading "Source Code for all Sample Programs".

I apologize if this issue is just due to my own 
ignorance.
Comment 1 tmanningtx 2004-10-23 19:03:44 UTC
Attached is the code in question.

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

/**
   This program tests input from a console window.
*/
public class ConsoleInputTest
{
   public static void main(String[] args) throws IOException
   {
      Purse myPurse = new Purse();


      BufferedReader console = new BufferedReader(
         new InputStreamReader(System.in));

      System.out.println("How many nickels do you have?");
      String input = console.readLine();
      int count = Integer.parseInt(input);
      myPurse.addNickels(count);

      System.out.println("How many dimes do you have?");
      input = console.readLine();
      count = Integer.parseInt(input);
      myPurse.addDimes(count);

      System.out.println("How many quarters do you have?");
      input = console.readLine();
      count = Integer.parseInt(input);
      myPurse.addQuarters(count);

      double totalValue = myPurse.getTotal();
      System.out.println("The total is " + totalValue);
   }
}

/**
   A purse computes the total value of a collection of coins.
*/
public class Purse
{
   /**
      Constructs an empty purse.
   */
   public Purse()
   {
      nickels = 0;
      dimes = 0;
      quarters = 0;
   }

   /**
      Add nickels to the purse.
      @param count the number of nickels to add
   */
   public void addNickels(int count)
   {
      nickels = nickels + count;
   }

   /**
      Add dimes to the purse.
      @param count the number of dimes to add
   */
   public void addDimes(int count)
   {
      dimes = dimes + count;
   }

   /**
      Add quarters to the purse.
      @param count the number of quarters to add
   */
   public void addQuarters(int count)
   {
      quarters = quarters + count;
   }

   /**
      Get the total value of the coins in the purse.
      @return the sum of all coin values
   */
   public double getTotal()
   {
      return nickels * NICKEL_VALUE 
         + dimes * DIME_VALUE + quarters * QUARTER_VALUE;
   }

   private static final double NICKEL_VALUE = 0.05;
   private static final double DIME_VALUE = 0.1;
   private static final double QUARTER_VALUE = 0.25;

   private int nickels;
   private int dimes;
   private int quarters;
}

Comment 2 Jan Chalupa 2004-11-08 21:39:41 UTC
Unfortunately true. This is a known defficiency of NB 4.0. Console 
apps run from the IDE can't receive input.

*** This issue has been marked as a duplicate of 47708 ***
Comment 3 Marian Mirilovic 2005-07-12 10:14:21 UTC
closed