ClassCastException:java.util.ArrayList cannot be cast to [message #754789] |
Fri, 04 November 2011 11:14 |
noviceEclipse Messages: 1 Registered: November 2011 |
Junior Member |
|
|
Hi folks,
Can somebody help me with this?
I am getting the following notification when I run my program in Eclipse:
Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to ie.ds.personApp.Person
at ie.ds.personApp.CrecheApp.searchPerson(CrecheApp.java:206)
at ie.ds.personApp.CrecheApp.main(CrecheApp.java:294)
It relates to the following line:
if(((Person) crecheArray).getFirstname().equalsIgnoreCase(firstname.getText())&&
in this method:
public void searchPerson(List<Person> crecheArray)
{
String PersonRecord = "";
String s0 = "First name:";
String s1 = "Surname:";
JTextField firstname = new JTextField("");
JTextField surname = new JTextField("");
Object message[] = new Object[4];
message[0] = s0;
message[1] = firstname;
message[2] = s1;
message[3] = surname;
JOptionPane.showConfirmDialog(null, message, "Search records",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,blankIcon);
///////////////////////////////////////////
//for(int i=0;i<count;i++)
// if(crecheArray[i].getFirstname().equalsIgnoreCase(firstname.getText())&&
// crecheArray[i].getLastname().equalsIgnoreCase(surname.getText()))
// childRecord+=crecheArray[i];
int i = 0;
///////////////////////////////////////////
for(Person registered:crecheArray)
if(((Person) crecheArray).getFirstname().equalsIgnoreCase(firstname.getText())&&
((List<Person>) crecheArray).get(i).getSurname().equalsIgnoreCase(surname.getText()))
PersonRecord+=crecheArray.get(i);
else
;
if(PersonRecord=="")
JOptionPane.showMessageDialog(null,"No Matching Records Found");
else
JOptionPane.showMessageDialog(null,PersonRecord,"Matching Records",JOptionPane.INFORMATION_MESSAGE);
}
Any help is much appreciated..
|
|
|
Re: ClassCastException:java.util.ArrayList cannot be cast to [message #754942 is a reply to message #754789] |
Sat, 05 November 2011 16:01 |
David Wegener Messages: 1445 Registered: July 2009 |
Senior Member |
|
|
On 11/04/2011 06:14 AM, noviceEclipse wrote:
> Hi folks,
> Can somebody help me with this?
> I am getting the following notification when I run my program in Eclipse:
>
> Exception in thread "main" java.lang.ClassCastException:
> java.util.ArrayList cannot be cast to ie.ds.personApp.Person
> at ie.ds.personApp.CrecheApp.searchPerson(CrecheApp.java:206)
> at ie.ds.personApp.CrecheApp.main(CrecheApp.java:294)
>
> It relates to the following line:
>
> if(((Person)
> crecheArray).getFirstname().equalsIgnoreCase(firstname.getText())&&
> in this method:
>
> public void searchPerson(List<Person> crecheArray)
> {
> String PersonRecord = "";
> String s0 = "First name:";
> String s1 = "Surname:";
>
> JTextField firstname = new JTextField("");
> JTextField surname = new JTextField("");
>
> Object message[] = new Object[4];
>
> message[0] = s0;
> message[1] = firstname;
> message[2] = s1;
> message[3] = surname;
>
> JOptionPane.showConfirmDialog(null, message, "Search records",
> JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,blankIcon);
> ///////////////////////////////////////////
> //for(int i=0;i<count;i++)
> //
> if(crecheArray[i].getFirstname().equalsIgnoreCase(firstname.getText())&&
> // crecheArray[i].getLastname().equalsIgnoreCase(surname.getText()))
>
> // childRecord+=crecheArray[i];
>
> int i = 0;
> ///////////////////////////////////////////
> for(Person registered:crecheArray)
> if(((Person)
> crecheArray).getFirstname().equalsIgnoreCase(firstname.getText())&&
> ((List<Person>)
> crecheArray).get(i).getSurname().equalsIgnoreCase(surname.getText()))
> PersonRecord+=crecheArray.get(i);
> else
> ;
> if(PersonRecord=="")
> JOptionPane.showMessageDialog(null,"No Matching Records Found");
>
> else
> JOptionPane.showMessageDialog(null,PersonRecord,"Matching
> Records",JOptionPane.INFORMATION_MESSAGE);
> }
>
> Any help is much appreciated..
This forum is for Eclipse specific questions. You asking a general Java
question. You should ask on a general Java forum.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08490 seconds