Results 1 to 3 of 3
- 01-12-2009, 08:01 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 19
- Rep Power
- 0
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
--------------------------------------------------------------------------
- 01-12-2009, 08:20 AM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Because you declare the array but don't define it. You still need a line in there that starts with
I'll let you attempt to finish that line.Java Code:mat =
Last edited by masijade; 01-12-2009 at 08:41 AM.
- 01-12-2009, 08:36 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 19
- Rep Power
- 0
Similar Threads
-
Complete code won't run in eclipse
By confusedStudent in forum New To JavaReplies: 2Last Post: 12-19-2008, 08:43 AM -
Download the Complete API?
By JDCAce in forum NetBeansReplies: 2Last Post: 10-02-2008, 01:02 AM -
Please complete the setRate mthod
By Adiel224 in forum New To JavaReplies: 6Last Post: 09-19-2008, 10:41 AM -
Error : Runnable did not complete within 10000ms
By piyushgpt1 in forum Advanced JavaReplies: 1Last Post: 02-05-2008, 07:04 PM -
Urgent-Imp-Displaying message with respect to system time
By garinapavan in forum New To JavaReplies: 1Last Post: 08-03-2007, 02:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks