我在这个 Point3f 数组上有一个空指针异常错误,不知道为什么。它发生在选择位置 [0] 的第一遍。有人可以解释一下吗?谢谢。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.vecmath.Point3f;
public class Starter {
static int NoOfSides = 4;
public static void main(String[] args) {
Point3f[] pointArray = new Point3f[NoOfSides];
for(int i=0; i<NoOfSides; i++)
{
System.out.println(i+1+". Input x value: ");
pointArray[i].x=readConsole(); // Pointer Exception Here
System.out.println(i+1+". Input y value: ");
pointArray[i].y=readConsole();
pointArray[i].z=(float)0.0;
}
// Static call to work out area of polygon
System.out.println("Area: "+PolyAreaTry.CalArea(pointArray));
}
public static float readConsole()
{
String s = null;
try
{
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
s = bufferRead.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
float f = (float)Float.parseFloat(s);
return f;
}
}