Look at how you create the data:
public Vector<Vector<Object>> convertMapToVector(Map<String, String> quesToAnsMap) {
if (quesToAnsMap.size() > 0) {
// the data field is initialized here
data = new Vector<Vector<Object>>(quesToAnsMap.size(), 1);
...
return data;
}
// but not here
return new Vector<Vector<Object>>();
}
My advices to make the code more robust:
- don't use a
data
field. It's not useful since the data is contained in the model already. So, to get the data, you just need to get it from the model. - either make all your method take arguments and return values, or not take anything, return void, and initialize fields, but mixing both is confusing. The method above initializes a field and returns it, but the else clause only returns it without initializing it.