1

I'm trying to create an array of objects in Java. "Point" is a class with two constructors and makes objects which are subclasses of it.

Point[] name = Point[1]; 
    for(int i=0; i < name.length; i++) { 
        name[i] = new Point(a, 40, 5, "green");
    }

I have a "cannot find symbol" error pointing to the second time is says Point.

Launch.java:10: error: cannot find symbol
Point[] name = Point[1]; 
               ^

This code however generates no errors.

Point name = new Point(a, 40, 5, "green");

Can anyone help me pinpoint the cause of this error?

1 Answer 1

3

Add the new keyword to initialize the array

Point[] name = new Point[1];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I don't know how nobody spotted that. I'll accept the answer after the minimum time is up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.