• Post Reply Bookmark Topic Watch Topic
  • New Topic

doubt in returning an array from one class to another  RSS feed

 
Arul Jose
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how will u return an array from one class to another?



class probabilityMatrix
{
double[][] getMatrix()
{
double[][] pm = new double[][];
// array manipulation
return pm;
}
}

class page
{
public static void main(String args[])
{
probabilityMatrix pm = new probabilityMatrix();
double pm1[][]=pm.getMatrix();
//print pm1[][];
}
}


This is what i have done in one of my programs. but it is showing the following error. i need help.


C:\Documents and Settings\Aruljose\Desktop>java page
Exception in thread "main" java.lang.NullPointerException
at probabilityMatrix.getMatrix(page.java:62)
at page.main(page.java:269)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile your code snippet, the only problem I have is in trying to create a new array without specifying the dimensions. ( double[][] pm = new double[][]; ) When I add dimensions, it's fine.

But I suspect your problem is elsewhere. Look at the line numbers in your error message...

at probabilityMatrix.getMatrix(page.java:62)
at page.main(page.java:269)
[ January 15, 2005: Message edited by: marc weber ]
 
Arul Jose
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is only an example that i have given.
in the original program, i have given the dimensions correctly.

jose.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!