java ArrayList 初始化为空?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13097512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ArrayList initializing as null?
提问by iaacp
Re-asking because my other thread wasn't clear and I didn't understand the true problem.
重新提问是因为我的另一个线程不清楚,我不明白真正的问题。
public class Test extends Survey
{
ArrayList<Answer> answerList;
ArrayList<Question> questionList;
public Test()
{
questionList = new ArrayList<Question>();
answerList = new ArrayList<Answer>();
...
}
...
}
In the eclipse debugger, it's showing answerList
value as null, while questionList
is not. What gives?
在 Eclipse 调试器中,它显示的answerList
值为 null,而questionList
不是。是什么赋予了?
Edit: Is it possible my debugger is messed up? I can't get it to stop where I'm setting break points. It's stopping at old ones and ignoring new ones. I didn't set up a new configuration or anything.
编辑:我的调试器有没有可能搞砸了?我无法让它在我设置断点的地方停下来。它停留在旧的,而忽略新的。我没有设置新的配置或任何东西。
回答by vikiiii
Keep your breakpoint on the next line to
将断点保持在下一行
answerList = new ArrayList<Answer>();
And then check answerList. Because If your breakpoint is on the initialization line, that line has not executed yet and the value will be null at that time.
然后检查answerList。因为如果你的断点在初始化行,那行还没有执行,那个时候值会是空的。
回答by onemach
Where is your breakpoint?
It makes perfect sense if it's in the line of answerList = new ArrayList<Answer>();
. When you set a breakpoint and eclipse breaks on it, everything you see is what you are beforethe execution of that line.
你的断点在哪里?如果它在answerList = new ArrayList<Answer>();
. 当你设置一个断点并且 eclipse 在它上面中断时,你看到的一切都是在执行该行之前的样子。