Results 1 to 3 of 3
  1. #1
    shaggyoo7 is offline Member
    Join Date
    Jan 2009
    Posts
    19
    Rep Power
    0

    Question Need help its Urgent need to complete in time,plz help anyone.................

    This is my code and it throws a NullPointerException in middle of execution
    --------------------------------------------------------------------------
    import java.io.*;
    class Matrix
    {
    static int mat[][], colSize, rowSize;
    public static void main(String args[])
    {
    try{
    System.out.println("Enter the size of the Matrix");
    BufferedReader a = new BufferedReader(new InputStreamReader(System.in));
    colSize = Integer.parseInt(a.readLine());
    BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
    rowSize = Integer.parseInt(b.readLine());
    System.out.println("Enter values in the matrix.");
    for(int i = 0 ; i < colSize ; i++)
    {
    for(int j = 0 ; j < rowSize ; j++)
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    mat[i][j] = Integer.parseInt(br.readLine());
    }
    }
    int ans = mat[0][0];
    for(int i = 0 ; i < colSize ; i++)
    {
    for(int j = 0 ; j < rowSize ; j++)
    {
    if(mat[i][j] > ans)
    ans = mat[i][j];
    }
    }
    System.out.println("The largest no is :"+ans);
    }catch(Exception e){System.out.println("The Exception is "+e);}

    }
    }
    --------------------------------------------------------------------------
    After running the code i get the following output
    --------------------------------------------------------------------------
    C:\Program Files\Java\jdk1.5.0\bin>java Matrix
    Enter the size of the Matrix
    3
    3
    Enter values in the matrix.
    The Exception is java.lang.NullPointerException
    --------------------------------------------------------------------------

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Because you declare the array but don't define it. You still need a line in there that starts with
    Java Code:
    mat =
    I'll let you attempt to finish that line.
    Last edited by masijade; 01-12-2009 at 09:41 AM.

  3. #3
    shaggyoo7 is offline Member
    Join Date
    Jan 2009
    Posts
    19
    Rep Power
    0

Similar Threads

  1. Complete code won't run in eclipse
    By confusedStudent in forum New To Java
    Replies: 2
    Last Post: 12-19-2008, 09:43 AM
  2. Download the Complete API?
    By JDCAce in forum NetBeans
    Replies: 2
    Last Post: 10-02-2008, 02:02 AM
  3. Please complete the setRate mthod
    By Adiel224 in forum New To Java
    Replies: 6
    Last Post: 09-19-2008, 11:41 AM
  4. Error : Runnable did not complete within 10000ms
    By piyushgpt1 in forum Advanced Java
    Replies: 1
    Last Post: 02-05-2008, 08:04 PM
  5. Urgent-Imp-Displaying message with respect to system time
    By garinapavan in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 03:17 PM

Posting Permissions

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