I have a generic class
public class GenericBookDet<K,V>
{
private K bkId;
private V bkDescription;
public GenericBookDet()
{
this.bkId = null;
this.bkDescription = null;
}
public GenericBookDet(K bkId, V bkDescription)
{
this.bkId = bkId;
this.bkDescription = bkDescription;
}
...
//getter methods
//setter methods
}
I have created an array of this class in another class and want to add new books.
public class GenericBookStore<K,V>
{
static int noOfbooks = 0;
GenericBookDet<K,V>bk1[];
public int addBook(K key, V bkDescription)
{
this.bk1[noOfbooks] = new GenericBookDet<K, V>(key,bkDescription);
this.bk1[noOfbooks].setbkDescription(bkDescription);
++noOfbooks;
return noOfbooks;
}
}
I am calling the addBook method in the following way :
GenericBookStore<String, String> bkStore = new GenericBookStore<String,String>();
bkStore.addBook("1010", "ABCD");
But this throws a NullPointerException at first line of the addBook method.
I want to create an generic book array in GenericBookStore to which I can pass String or and object in bkDescription field;