mahaMutant
Programmer
Hi;
I have an ADT 'person' implemented using a singly linked list.
In the SLL class I have a print method, called from the client driver, which receives 2 SLL's - appends the lists then passes the result list to a method which prints the content of the list.
Example:
// from class PRecord
public void mergeLists(PRecordSLL MLlist1, PRecordSLL MLlist2)
//
{
while (MLlist2.first != null)
{
MLlist1.addElement(MLlist2.first);
MLlist2.first = MLlist2.first.succ;
}
MLlist1.printThisList();
}
public void printThisList()
//cast & print all the elements in the list
{
SLLNode curr = this.first;
if (this.first == null) System.out.println ("No record."
;
else
{
System.out.print("Name\tSurname\tGender\n"
;
for (; curr != null; curr = curr.succ)
{
System.out.print(((Person)curr.element).theName + "\t"
;
//System.out.print(((Person)curr.element).theSurname + "\t"
;
//System.out.print(((Person)curr.element).theGender + "\n"
;
}
}
}
///////////// end of example
The for loop itterates through the list and prints the values, the weird thing is;
The values in the 1st list prints fine (being casted to ADT 'Person') but when the loop reaches the append nodes I get a class cast exception.
Here is my result:
java.lang.ClassCastException: project.PRecordSLL$SLLNode
at project.PRecordSLL.printThisList(PRecordSLL.java:135)
at project.PRecordSLL.mergeLists(PRecordSLL.java:111)
at project.Info_drv.displayTransAll(Info_drv.java:322)
at project.Info_drv.main(Info_drv.java:90)
Exception in thread "main"
I have tried sooo many things I am at a totl loss and depressed. Any help would be VEEERRRYYYYYYYYY appreciated.
Cheers in adv; ] always a sucker to the greatest lie of all: will only take a minute [
I have an ADT 'person' implemented using a singly linked list.
In the SLL class I have a print method, called from the client driver, which receives 2 SLL's - appends the lists then passes the result list to a method which prints the content of the list.
Example:
// from class PRecord
public void mergeLists(PRecordSLL MLlist1, PRecordSLL MLlist2)
//
{
while (MLlist2.first != null)
{
MLlist1.addElement(MLlist2.first);
MLlist2.first = MLlist2.first.succ;
}
MLlist1.printThisList();
}
public void printThisList()
//cast & print all the elements in the list
{
SLLNode curr = this.first;
if (this.first == null) System.out.println ("No record."
else
{
System.out.print("Name\tSurname\tGender\n"
for (; curr != null; curr = curr.succ)
{
System.out.print(((Person)curr.element).theName + "\t"
//System.out.print(((Person)curr.element).theSurname + "\t"
//System.out.print(((Person)curr.element).theGender + "\n"
}
}
}
///////////// end of example
The for loop itterates through the list and prints the values, the weird thing is;
The values in the 1st list prints fine (being casted to ADT 'Person') but when the loop reaches the append nodes I get a class cast exception.
Here is my result:
java.lang.ClassCastException: project.PRecordSLL$SLLNode
at project.PRecordSLL.printThisList(PRecordSLL.java:135)
at project.PRecordSLL.mergeLists(PRecordSLL.java:111)
at project.Info_drv.displayTransAll(Info_drv.java:322)
at project.Info_drv.main(Info_drv.java:90)
Exception in thread "main"
I have tried sooo many things I am at a totl loss and depressed. Any help would be VEEERRRYYYYYYYYY appreciated.
Cheers in adv; ] always a sucker to the greatest lie of all: will only take a minute [