I have QStorage class that stores the Queue contents.
class QStorage{
Queue<A> q = new PriorityQueue<A>(5);
public Queue<a> readQ(){
try{
FileInputStream fin = new FileInputStream("/home/requestQ.ser");
ObjectInputStream ois = new ObjectInputStream(fin);
q = (Queue)ois.readObject();
}catch(Exception e){}
return q;
}
}
And in another class I am calling readQ() method of above class to store the queue content of the file to some another queue.
class MyQ{
public static void main(String args[]){
QueueStorage qs = new QueueStorage();
Queue<A> myQ = new PriorityQueue<A>(5);
myQ = qs.readQ();
//...some other stuffs goes here
}
}
Here if already some entries of the queue are stored in file, readQ() correctly returns those entries. But if there are no entries stored in file(i mean the empty queue is stored) then this method gives nullPointerException and my program stops working.
Note: I have the requirement that I should check the stored contents without knowing if it is empty or not.
Please help. Thanks.