NullPointerException while using Vector<>
1.
public class MPoll {
private Vector<MQuestion> q1;
...
q1.add(1,y); // Raises NullPointerexception
...
2.
...
private MQuestion q2[];
...
q2[0] = new MQuestion(); .// Raises NullPointerException
...
Message was edited by:
BrotherFlame
# 1
1. It looks like the variable q1 has not been initialized and is therefore null when 'q1.add(1,y)' statement is executed. You can confirm this by putting the following statement:
if (q1 == null) System.out.println("q1 is null");
q1.add(1,y);
2. Similarly the array q2 has not been initialized prior to accessing it.