I have two files, a Section class, for a specific department in a store, and a Dept class, representing a collection of Section classes. I am having trouble accessing methods of the Section class (like getName() or printNameArrList()) AFTER I add the Section objects to the Dept's sectionArr. The methods seem to work when they are instantiated in main, but I get the "error: cannot find symbol" when I try to access anything with store.sectionArr[0].anything()
Section.java
import java.util.ArrayList;
import java.util.Arrays;
public class Section {
public static String name;
public static ArrayList<String> arrList;
public void setName(String text) {
name = text;
}
public String getName() {
return name;
}
public ArrayList getArrList() {
return arrList;
}
public void printNameArrList() {
System.out.print("The " + name + " section sells these items: ");
for (int i = 0; i < arrList.size(); i++) {
String value = arrList.get(i);
System.out.print(value + " ");
}
System.out.println();
}
public static void main(String[] args) {
}
}
Dept.java
import java.util.Arrays;
import java.util.ArrayList;
public class Dept {
public static String name;
public Object[] sectionArr;
public void setName(String text) {
name = text;
}
public String getName() {
return name;
}
public Object[] getObjArr() {
return sectionArr;
}
public void initArr(int size) {
sectionArr = new Object[size];
}
public static void main(String[] args) {
Dept store = new Dept();
store.setName("Floyd's Floors");
System.out.println(store.getName());
System.out.println(store.getObjArr());
store.initArr(3);
System.out.println(store.getObjArr());
Section sec1 = new Section();
sec1.setName("Shoes");
sec1.arrList = new ArrayList<String>();
sec1.arrList.add("Jordan's");
sec1.arrList.add("Rodman's");
sec1.arrList.add("Shaq's");
sec1.getArrList();
sec1.printNameArrList();
store.sectionArr[0] = sec1;
for (int i = 0; i < store.sectionArr.length; i++) {
System.out.println(store.sectionArr[i]);
}
Object secX = store.sectionArr[0];
secX.printNameArrList();
}
}