Null pointer exception for Array of Objects

后端 未结 4 905
长情又很酷
长情又很酷 2020-12-22 09:55

I am new to using arrays of objects but can\'t figure out what I am doing wrong and why I keep getting a Null pointer exception. I am trying to create an Theatre class with

4条回答
  •  天涯浪人
    2020-12-22 10:18

    When you do "arrayOfSpotlights = new spotlight[N];" you init an array of length N, what you need to do is also init each object in it:

    for i=0; i

    Hope I'm correct :)

提交回复
热议问题