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

[332 byte] By [BrotherFlamea] at [2007-11-27 0:32:40]
# 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.

KarthikRa at 2007-7-11 22:38:59 > top of Java-index,Development Tools,Java Tools...