This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 请大师们指点: Java里调用这句 stateDiagram.readLine().trim()时,老抛出java.lang.NullPointerException的错误.原码是这样的:
String s = "";
while (stateDiagram.ready() && !s.equals("(*** TRANSITIONS***)")) {
s = stateDiagram.readLine();
}
do {
s = stateDiagram.readLine().trim();
}
while (stateDiagram.ready() && s.equals(""));
如果我把do...while 这一块提前到String s = ""下面写的话,就不会出这样的错,实在想不明白是为什么? 但我又不能更改程序结构.
-rlm007(舒服斯基);
2004-11-8
{399}
(#1970793@0)
-
stateDiagram的readLine指针在第一个while执行完后已经到了最末,你在do里面readLine会得到一个null,然后trim,就会得到nullpointexception,嘿嘿,猜的。
-xanada(㊣流水);
2004-11-8
(#1970802@0)
-
The following content might contain wrong English expressions, fatal errors and misspellings, viewers discretion is advisedIf there's no content after "(*** TRANSITIONS***)" or merely no "(*** TRANSITIONS***)" in the source file, this program would throw NullPointerException
If either of the conditions above is met, in the first loop, the program will go through the whole content of the file and the last time excution of the "readLine()" will make the pointer move to the end of the file. Therefore the "readLine()" in the second loop will return you a "null", then.....
-fatbean(泥腿上炕抽袋烟);
2004-11-8
{465}
(#1970958@0)