运行时期间数组列表出现空指针异常,但调试模式下则不然
我的类中有一个数组列表,并且正在获取它的值,因为
ArrayList<VenueIcons> venueArrays = TourDescription.currentTour.getVenues();
我在 for 循环中使用这个数组
for (VenueIcons objVenues : venueArrays) {
}
问题是,当我处于调试模式时这工作正常,但是当我尝试运行它时它会抛出同一数组的空指针异常。
当我调试它时,我毫无问题地获得了venueArrays的所有值。
试图找出问题所在
I have an array list in my class and am getting the value for it as,
ArrayList<VenueIcons> venueArrays = TourDescription.currentTour.getVenues();
I am using this array in my for loop
for (VenueIcons objVenues : venueArrays) {
}
The problem is, this works fine when I am in the debug mode, but when I try to run it it throws null pointer exception for the same array.
When I debug it, I get all the values for venueArrays without any problem.
Trying to find what went wrong
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该给予一些延迟时间来获取 http 调用的响应。它应该可以工作。
You should give some delay time for getting response for your http call.It should work.
当您处理基于时间的操作时,通常会发生这种情况。 getVenues() 方法很可能需要一些时间才能填满数组。因此,当您处于调试模式时,它有足够的时间来执行此操作。在其他情况下,它只返回 null。您可以尝试在调用 getVenues() 之前插入“睡眠”。然后观察 getVenues() 方法中实际发生的情况。
希望这有帮助。
This usually happens when you are dealing with a time based operation. Most probably getVenues() method needs some time in order to fill up the array. So when you are in debug mode it has enough time to do that. In other case it just returns null. You may try to insert a 'sleep' before calling getVenues(). Then observe what is actually happening in getVenues() method.
Hope this helps.