I’m working to create an array of instances of the class in itself.
class A (arg: Int) {
var a1 = new Array[A] (arg)
....
}
declaring it this way gives “java.lang.NullPointerException” during run-time. Is there any way to remove this exception?
I’m sure that you are trying to access elements of array a1 later in your code. There you get your exception.
I’ve prepared small chunk of code to demonstrate it: