• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt in returning an array from one class to another

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic