我有这段代码,但是当我运行它时,它只会给我一个NullPointerException
import javax.swing.JOptionPane;
public class System {
public static void main(String[] args) {
int a=Integer.parseInt(JOptionPane.showInputDialog("How many planets"));
Planet p[]=new Planet[a];
for (int i=1;i<=a;i++){
** p[i].setName("romain"); **
//line bugging is above
}
//for info the .setName method of the Planet class is
/*public void setName(String Na){
name=Na;
}*/
}
}
所以我的问题是:你能用增量器作为数组引用吗