Results 1 to 2 of 2
Thread: Problem with LinkedList
- 07-05-2007, 06:06 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 111
- Rep Power
- 0
Problem with LinkedList
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..
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)Java Code:// 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; } } }
Can anyone help me to solve this problem??Java Code:PhotoNode oldPhotoListCurrent, newPhotoListCurrent; PhotoManager newPhotoList = new PhotoManager(); oldPhotoListCurrent = photoManager.head; newPhotoList.head = null; while(oldPhotoListCurrent != null) { newPhotoList.addPhoto(oldPhotoListCurrent.photo, 1); oldPhotoListCurrent = oldPhotoListCurrent.next; }
Thanks
Eric
- 07-05-2007, 06:08 AM #2
Member
- Join Date
- Jun 2007
- Posts
- 91
- Rep Power
- 0
I confess I only took a quick look at this, but I thought I'd point something out in case it helps.
In addPhoto method
As far as I can tell, the variable previous will always be null when you hit this if-condition as it doesn't seem that it's ever set otherwise after you declare it as null.Java Code:PhotoNode current = head, previous = null; // di sini .... if(previous == null) { newNode.next = head; head = newNode; }
So, I'm not sure this is what you had intended. Just thought I'd point it out.
Greetings
Daniel:o
Similar Threads
-
Making a stack from a LinkedList
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 10:28 PM -
Problem with LinkedList Java
By paul in forum Advanced JavaReplies: 2Last Post: 08-07-2007, 04:57 AM -
Please help me with LinkedList in Java
By lenny in forum New To JavaReplies: 2Last Post: 07-31-2007, 02:24 PM -
how to use LinkedList
By fred in forum Advanced JavaReplies: 1Last Post: 07-24-2007, 01:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks