我是 Java 新手,正在从事一个小型学习项目,但我被困住了。我试图弄清楚为什么 for 循环在 MyApp.main(MyApp.java:26) 的线程“main”java.lang.NullPointerException 中生成异常。谁能解释我做错了什么?我非常感谢您的帮助!
// Create array of toddlers
babyMikeyToddler[] toddlercollection = new babyMikeyToddler[4];
toddlercollection[0] =new babyMikeyToddler("Baby Mikey",10,2);
toddlercollection[1] =new babyMikeyToddler("Baby Mikey",10,2);
toddlercollection[2] =new babyMikeyToddler("Baby Mikey",10,2);
for(int i =0; i < toddlercollection.length; i++)
{
System.out.println(toddlercollection[i].getName());
}
}
}