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.
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.
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; }
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 ***
closed