I have a SerializableEnumeration and I am trying to add a vector elements into that SerializableEnumeration. Below is the code.
if(objTempVector !=null)
{
CommonUtils.log("objTempVector:::::::::::::::::::::: objTempVector not null::::");
try{
hlpOrder.mOrderDetail = new SerializableEnumeration(objTempVector);
}
catch(NullPointerException ex)
{
CommonUtils.log("Exception in SerializableEnumeration::::::::::::::::::::::" + ex.toString());
}
}
but even though the vector is not null , the above code is generating null pointer exception.
error log: Exception in SerializableEnumeration::::::::::::::::::::::java.lang.NullPointerException
this is the method for SerializableEnumeration
public SerializableEnumeration(Vector data) {
if (data == null) {
size = 0;
} else {
this.data = data.toArray();
this.size = data.size();
}
i = 0;
}
Please help me to fix the problem.
This the whole class for SerializableEnumeration
import java.io.Serializable;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.Vector;
public class SerializableEnumeration implements Enumeration, Serializable {
private static final long serialVersionUID = 1L;
private Object[] data = null;
private int i;
private int size;
public SerializableEnumeration(Vector data) {
if (data == null) {
size = 0;
} else {
this.data = data.toArray();
this.size = data.size();
}
i = 0;
}
public boolean hasMoreElements() {
return ((size > 0 ) ? true : false);
}
public Object nextElement() throws NoSuchElementException {
try {
Object element = data[i];
++i;
--size;
return element;
} catch (Exception e) {
throw new NoSuchElementException();
}
}
public int getSize() {
return size;
}
public void reset(){
if(data==null){
size=0;
}else{
size=data.length;
i=0;
}
}
}
I am using the variable in a JSP File and when I trying to use the Enumeration I am getting the below error: