我正在尝试将 2 个子类对象添加到超类对象的静态集合中。但是,当我尝试将对象添加到集合中时,我收到了一个空指针异常,我试图找出原因。
public class MoverLogic{
static Collection<Super> superCollection;
public static void main(String[] args) {
SubAlpha sub1 = new SubAlpha();
SubBeta sub2 = new SubBeta();
superCollection.add(sub1); //I'm getting the null pointer exception here
superCollection.add(sub2);
}