Results 1 to 2 of 2
  1. #1
    thatguy is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default 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

    Java Code:
    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");
            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
    the error message i recieve is :

    Java Code:
    C class calculator
    Exception in thread "main" java.lang.NullPointerException
            at timeonc.Main.main(
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)
    but i cant find what the problem is

    any hep would be greatly appreciated

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Rep Power

    Default Works fine for me

    Compiled the code(Java SE 6, command line), ran it, worked fine.

    • 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.

    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. [SOLVED] ReadLine(String fmt,Object... args) of Console class
    By Pooja Deshpande in forum New To Java
    Replies: 4
    Last Post: 04-25-2008, 05:51 AM
  2. Console doesn't appear!
    By PeteMarsh in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 05:41 PM
  3. DataInputStream readLine()
    By ravian in forum New To Java
    Replies: 2
    Last Post: 11-26-2007, 10:44 PM
  4. Problems with readLine() and calling methods
    By peachyco in forum New To Java
    Replies: 2
    Last Post: 11-24-2007, 07:44 AM
  5. BufferedReader: readLine method problems
    By bbq in forum Advanced Java
    Replies: 2
    Last Post: 06-30-2007, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts