Results 1 to 2 of 2
  1. #1
    bluebarca is offline Member
    Join Date
    Nov 2007
    Posts
    5
    Rep Power
    0

    Default NumberFormatException problem

    i've a problem with my program; its supposed to read an input line that states the number of lines to follow; then after that for-loop on these lines reading integer values and making a mathematical function on them then saving them in an int array named output;

    test case:
    2
    10
    10
    after the first 10 the program exits with an exception !



    here is the code:





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

    public class Main{

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static int[]output;
    static int lines;

    static int input = 0;


    public static void getZeroes() throws Exception{

    lines = Integer.parseInt(in.readLine());



    output = new int[lines];
    int lines2;

    lines2 = Integer.parseInt(in.readLine());
    System.out.println(lines2);

    for(int i = 0;i<lines;i++){



    //input= Integer.parseInt(in.readLine());

    output[i] = (lines2/5);


    }






    for(int j = 0;j<output.length;j++){
    System.out.println(output[j]);
    }



    }



    public static void main(String[] args) throws Exception {

    getZeroes();



    }

    }








    thanx for the help;

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    10

    Default

    If you analyze the stack trace, it will tell you exactly what kind of problem was encountered, and the exact line where it happened. I don't see anything obviously wrong, but my guess is that readLine is returning null, which is a valid possibility you are not handling.

Similar Threads

  1. Replies: 2
    Last Post: 08-07-2007, 03:50 PM
  2. Error: NumberFormatException
    By coco in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:41 AM
  3. java.lang.NumberFormatException: null
    By Eric in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-05-2007, 05:31 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
  •