我有得到回报型传感器 在大胆的方法是在那里我得到一个NullPointerException异常运行时,不明白为什么。NullPointerException异常的方法
public Sensor getSensorAt(int x,int y,GridMap grid)
{
/*go through sensor storage array
* for eachsensor index call the get x get y method for that
* compare it to the x,y of the robot
*
*/
for(int i=0;i<s1.length;i++){
if(s1[i].getX() == x){ <======= NullpointerException
if(s1[i].getY()== y){
return s1[i];
}
}
}
return null;
}
因为有些东西是'null'。但是不可能说出什么,因为你没有向我们展示过如何声明's1',初始化等。 – 2012-02-01 00:14:17
s1 [i]为空。找出为什么它不是在你期望的地方创造的。 – 2012-02-01 00:14:29