Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » ClassCastException:java.util.ArrayList cannot be cast to
ClassCastException:java.util.ArrayList cannot be cast to [message #754789] Fri, 04 November 2011 11:14 Go to next message
noviceEclipse  is currently offline noviceEclipse Friend
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 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1441
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.
Re: ClassCastException:java.util.ArrayList cannot be cast to [message #754958 is a reply to message #754789] Sat, 05 November 2011 20:58 Go to previous messageGo to next message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2011.11.04 5:14, noviceEclipse wrote:
> Hi folks,
> Can somebody help me with this?
> I am getting the following notification when I run my program in Eclipse:
>
>[snip]

I'd personally suggest JavaRanch.com or stackoverflow.com.
Re: ClassCastException:java.util.ArrayList cannot be cast to [message #754976 is a reply to message #754958] Sun, 06 November 2011 09:40 Go to previous message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
> I'd personally suggest JavaRanch.com or stackoverflow.com.

And if you do so, I suggest to post code that nicely conforms to the
"Code Conventions for the Java Programming Language" [1] as it is more
pleasant to read which drastically increases your chance for an answer.

[1] http://www.oracle.com/technetwork/java/codeconv-138413.html

Michael
Previous Topic:UnsupportedOperationException
Next Topic:The jar file cannot be exported into itself
Goto Forum:
  


Current Time: Tue Jun 22 15:27:42 GMT 2021

Powered by FUDForum. Page generated in 0.03247 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top