mainMethod.java
public class mainMethod{
public animalsData[] animals;
public mainMethod(){
animals[this.animals.length + 1] = new animalsData("CAT", "4");
}
public static void main(String[] args) {
mainMethod run = new mainMethod();
}
}
animalsData.java
public class animalsData{
String name, l;
public animalsData(String name, String l) {
super();
this.name= name;
this.l= l;
}
}
I hava this problem: Exception in thread "main" java.lang.NullPointerException
animalshas not been assigned a value. Now that you know what the problem is, please delete and/or help me close this question. (P.S. there are many such related questions. Try searching first for "ideas" about what could be wrong.)animals?nullso it's not possible to acces length propertyarr[arr.length + 1]is never valid in Java because arrays have a fixed length.