# Problem with return and 2D array

• March 21st, 2013, 11:01 PM
J-moges
Problem with return and 2D array
Hello, first time on a programming forum, hopefully this is in the right place and I inserted the code correctly. Anyway, I am having trouble figuring out what the problem is in the code below. I return the array and in my next line of my main method when I try to use the returned array "pointArray" I am getting an error that says "cannot find symbol". Am I misunderstanding how the return statement should return? Been trying things for the last few hours and I haven't found a solution. Still pretty new to programming, trying to learn but I don't know what else to do debugging wise.

I can post my other class if necessary but I didn't think it was. Let me know.

Thanks

Code :

```public class ManyCircles {   /** * @param args the command line arguments */ public static void main(String[] args) { randomPoints(5); //averagePoint(pointArray);   printPoints(pointArray); //After I return from randomPoints I get a "Cannot find symbol" error here for pointArray }   public static Point1080[][] randomPoints(int n) { int x; int y; //Declares 2D array Point1080[][] pointArray = new Point1080[n][2]; //Goes through n elements of the array for (int i = 0; i < pointArray.length; i++) { //For n element, give x and y values in 2nd array for (int j = 0; j < 2; j++) { x = (int) ((int) 1920 * Math.random()); y = (int) ((int) 1080 * Math.random()); pointArray[i][j] = new Point1080(x, y); } System.out.println("X " + i + " is: " + pointArray[i][0].getX()); System.out.println("Y " + i + " is: " + pointArray[i][1].getY());   } //Should return the 2D array, not returning it to main method though return pointArray; }   private static void printPoints(Point1080[] V) { for (Point1080 E : V) { System.out.format("(%4d,%4d)\n", E.getX(), E.getY()); }```
• March 21st, 2013, 11:12 PM
Junky
Re: Problem with return and 2D array
Your code may have returned the array but it does nothing with it and it disappears into the ether.
• March 21st, 2013, 11:33 PM
J-moges
Re: Problem with return and 2D array
Oh, so do I need to re-declare the array? I want to use the array later. This 2D array stuff is confusing me some. I am trying to think of it like I am just returning an integer or string. I am putting a random value in the second part of the array (don't know what you call it).
• March 21st, 2013, 11:45 PM
Junky
Re: Problem with return and 2D array
No. All you need to do is assign the returned array to a variable.
• March 21st, 2013, 11:53 PM
J-moges
Re: Problem with return and 2D array
Ooooooooohhh...I see. Thanks for the help. Now I get what you meant by does nothing with it.