I work on a project that stores my Items , Persons and action when I Borrow some Item to some Person
This project is based on a YouTube tutorial for classical library of books.
I'm sorry for I will post some more code because I want to give some idea how I'm doing it. I personally think that there is a problem with how I get the instances of ItemClass or PersonClass. Or something with inheritance around BorrowClass.
Now first two Methods in BorrowClass works okay, creating items and persons and adding to the lists, but when I try to create new BorrowClass containing and instance of items or persons it throws nullPointer, yet through debug I was able to see borrowed in variables and everything seemed to be not null or does the red squares means problem ?
I create ItemClass
public class ItemClass implements Serializable {
private static final long serialVersionUID = 1L;
private int isbn;
private String title, author;
private String otherInfo;
public ItemClass(String title,String otherInfo, String author,int isbn) {
this.isbn = isbn;
this.title = title;
this.author = author;
this.otherInfo = otherInfo;
}
Then PersonClass
public class PersonClass implements Serializable {
private static final long serialVersionUID = 1L;
private int telephone;
private String name, surename, email;
public PersonClass(String name,String surename, int telephone,String email) {
this.name = name;
this.surename = surename;
this.telephone = telephone;
this.email = email;
}
Then BorrowCLass
public class BorrowClass implements Serializable {
private static final long serialVersionUID = 1L;
private ItemClass item;
private PersonClass person;
private Date borrowDate;
private Date expireDate;
public BorrowClass(ItemClass item, PersonClass person, Date borrowDate,
Date expireDate) {
this.item = item;
this.person = person;
this.borrowDate = borrowDate;
this.expireDate = expireDate;
}
Now All above I handle in Library class
public class Library extends Object implements Serializable {
private static final long serialVersionUID = 1L;
private List<ItemClass> listOfItems;
private List<PersonClass> listOfPersons;
private List<BorrowClass> listOfBorrowed;
public Library() {
listOfItems = new ArrayList<ItemClass>();
listOfPersons = new ArrayList<PersonClass>();
listOfBorrowed = new ArrayList<BorrowClass>();
}
public void addItemtoItemsCollection(ItemClass item) {
listOfItems.add(item);
}
public void addPersontoPersonCollection(PersonClass person) {
listOfPersons.add(person);
}
public void addBorrow(BorrowClass borrowed) {
listOfBorrowed.add(borrowed);
}
Also would be nice if someone could explain the meaning of
private static final long serialVersionUID = 1L;
because in the video I didn't get it and I would like to know.
Thanks for any answer.