
public class tn {
public class State{
String s_name;
int p1;
int p2;
}
public void f(){
State[] s = new State[10];
int [] i = new int[10];
i[0] = 1; //right
s[0].p1 = 1; //error NullPointerException
}
public static void main(String[] args) throws Exception {
tn t = new tn();
tn.f();
}
Can anyone help me in 2 comment line, why s[0].p1 = 1 is NullPointerException ???

* State[] s = new State[10];* I don't think that's ok . Try using a Vector or an Array of objects something like Vector<State>=new Vector<State>();
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.