我是java编程的初学者。我想开发一个程序,但是当我跑我的程序,它被张贴下方,它回来了与此错误:线程“main”中的异常java.lang.NullPointerException
Exception in thread "main" java.lang.NullPointerException at dist.main(dist.java:13)
import java.lang.Math;
class Point {
int x; int y;
}
public class dist {
public static void main(String[] args) {
Point[] pt = new Point[3];
pt[0].x = 40; pt[0].y = 40;
pt[1].x = 40; pt[1].y = 30;
pt[2].x = 26; pt[2].y = 30;
for(int i = 0 ;i < pt.length ; i ++){
pt[i] = new Point();
}
int ux = pt[0].x - pt[1].x;
System.out.println("ux:" + ux);
}
}
请看看[Java代码的惯例(http://www.oracle.com/technetwork/的java/codeconv-138413.html)。班级名称以大写字母开头。 –
你是否编译过这段代码,并声明变量'n'。 –
按照Nodebody告诉的说明操作。他很好地解释为初学者。 –