This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 为什么会提示Exception in thread "main" java.lang.NullPointerException?在线等.谢谢
-happy-day(想去玩);
2003-11-24
{799}
(#1482039@0)
-
you defined custArray but never assign a value to it, so it is null. The system can not get the value custArray.length.
-guestagain(guest again);
2003-11-24
(#1482256@0)
-
我在开始一经初始话这个数组了.不是吗? for (int j=0; j<custArray.length; j++){custArray[j].arrivalTime=j;custArray[j].length=2*j;}
-happy-day(想去玩);
2003-11-24
(#1482486@0)
-
In Java, array should be created in this way: Customer [] custArray = new Customer[10];
-yuanml(加拿大的家);
2003-11-24
(#1482496@0)
-
你的程序有两个错误,都会引起NullPointerException1、如yuanml所描述,数组没有初始化;
2、数组元素没有初始化;
正确程序应该如下:
Customer[] custArray = new Customer[COUNT];
for(int j = 0; i < custArray.length; j++)
{
custArray[j] = new Customer();
custArray[j].arrivalTime = j;
custArray[j].length = 2 * j;
}
-exception(违例);
2003-11-24
{267}
(#1483073@0)
-
如果我事先没法知道数组里有多少成员,怎么办?
-happy-day(想去玩);
2003-11-26
(#1485267@0)
-
try to use dynamic container instead of array in this case: like ArrayList, Vector, ...
-yuanml(加拿大的家);
2003-11-26
(#1485291@0)
-
用 ArrayList 是最方便的
-null(Null Pointer);
2003-11-26
(#1485294@0)
-
ArrayList比Vector效率高一些,但要自己作同步。如果不存在同步问题,就用它吧。
-exception(违例);
2003-11-26
(#1485352@0)