Hi.. I have a problem 'bout single linkedlist..
In my list class (
PhotoManager), I create a method to storing the data in ascending order.
When i compile, it gives me no error.. but when i run it, it gives me null pointer exception..
// 1 indicates order by increasing date/time order
else if(photoOrder == 1) {
if(current == null) {
newNode = new PhotoNode(newPhoto);
newNode.next = head; // di sini
head = newNode; // di sini
}
else {
while(current != null) {
if(current.photo.getDatePhotoTaken().compareTo(newNode.photo.getDatePhotoTaken()) <= 0) {
previous = current;
current = current.next;
}
else {
break;
}
}
if(previous == null) {
newNode.next = head; // di sini
head = newNode; // di sini
}
else {
previous.next = newNode;
newNode.next = current;
}
}
}
i'm gonna use that method in my main class, that is make use of the current list (listed in random order) to create a new list (in ascending order)
PhotoNode oldPhotoListCurrent, newPhotoListCurrent;
PhotoManager newPhotoList = new PhotoManager();
oldPhotoListCurrent = photoManager.head;
newPhotoList.head = null;
while(oldPhotoListCurrent != null) {
newPhotoList.addPhoto(oldPhotoListCurrent.photo, 1);
oldPhotoListCurrent = oldPhotoListCurrent.next;
}
Can anyone help me to solve this problem??
Thanks
Eric