不明白它为何没有指向
class Demo{
public int num;
public boolean mark;
}
class ImprovedPartialSum
{
public Demo[] vertices=new Demo[10];
public void get()
{
int s=0;
for(int i=1;i<=10;i++)
{
s=s+i*i;
vertices[i-1].num=i;
if(s%2==0) vertices[i-1].mark=true;
else vertices[i-1].mark=false;
}
}
public void print()
{
for(int i=0;i<10;i++)
{
if(vertices[i].mark==true) System.out.println(vertices
[i].num+"*");
else System.out.println(vertices[i].num);
}
}
public static void main(String[] args)
{
ImprovedPartialSum string=new ImprovedPartialSum();
string.get();
string.print();
}
}
编译通过。运行时提示exception in thread "main"java.lang.NullPointerException(get.()和main()两部分)