-1
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size = 5;
Point2D.Double[] p;
p = new Point2D.Double[size];
for(int i = 0; i < size; i++) {
System.out.println("Please enter x of vertice " + (i + 1) + ":");
p[i].x = input.nextDouble();
System.out.println("Please enter y of vertice " + (i + 1) + ":");
p[i].y = input.nextDouble();
}
}
我其实并没有弄错这些代码出了什么问题。 NullPointerException总是发生在“p [i] .x = input.nextDouble()”。任何帮助将不胜感激。如何解决这个关于空指针异常的问题
我敢打赌,P [i]为null,因为p在未初始化。仅仅因为你说p有尺寸元素,并不意味着它的所有位置都填充了Point2D.Double类型的初始化对象 – Leo 2014-09-22 22:35:39