Results 1 to 2 of 2
Thread: problem with console.readLine()
- 12-14-2008, 05:41 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 1
- Rep Power
- 0
problem with console.readLine()
I am trying to write a simple program to keep track of the time I spend taking a C++ class and here is the begginings of the program
the error message i recieve is :Java Code:import java.io.Console; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Console console = System.console(); // declare console int counter, x = 0; //variables for while loop String inputTime, inputClassSec; //variable for input System.out.println("C class calculator"); System.out.println("********************************"); String counterS = console.readLine("Completed sections since last entry: "); counter = Integer.parseInt(counterS); while (x < counter) { inputClassSec = console.readLine("class section name: "); //get input on the name of the class inputTime = console.readLine("time spent: "); //get input on time spent on the section } } }
but i cant find what the problem isJava Code:run: C class calculator ******************************** Exception in thread "main" java.lang.NullPointerException at timeonc.Main.main(Main.java:19) Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)
any hep would be greatly appreciated
- 12-14-2008, 07:40 PM #2
Works fine for me
Compiled the code(Java SE 6, command line), ran it, worked fine.
Suggestions:
- You're going to need to save the values... probably in an array list.
- Would be nice if you had a graceful way of exiting the while loop. Maybe when inputClassSec equals "0" (or something like that), print values and exit program.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
[SOLVED] ReadLine(String fmt,Object... args) of Console class
By Pooja Deshpande in forum New To JavaReplies: 4Last Post: 04-25-2008, 05:51 AM -
Console doesn't appear!
By PeteMarsh in forum New To JavaReplies: 2Last Post: 12-17-2007, 05:41 PM -
DataInputStream readLine()
By ravian in forum New To JavaReplies: 2Last Post: 11-26-2007, 10:44 PM -
Problems with readLine() and calling methods
By peachyco in forum New To JavaReplies: 2Last Post: 11-24-2007, 07:44 AM -
BufferedReader: readLine method problems
By bbq in forum Advanced JavaReplies: 2Last Post: 06-30-2007, 02:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks