java.util.Vector<EmergencyContacts.ContactInfo> contacts = Application.getPatient().readEmergencyContacts().readContactInfos();
for (int i = 0; i < contacts.size(); i++){
            EmergencyContacts.ContactInfo info = contacts.get(i);

public Vector<ContactInfo> readContactInfos(){
		return contacts;

	private Vector<ContactInfo> contacts = new Vector<ContactInfo>();

As you can see, it returns a Vector of ContactInfo. Why would I be getting an error saying, "Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to repository.EmergencyContacts$ContactInfo" for the line where it says . . . contacts.get(i)?

Also, if it matters, ContactInfo is an inner class of EmergencyContacts. Hence above where you can see it say readEmergencyContacts.readContactInfos. There is only one Object of type EmergencyContacts, which has the Vector of ContactInfo (which I posted in the code). And everything is Serializable.

7 Years
Discussion Span
Last Post by quuba

Someone else coded what i was referring to above, but since either

a) it doesn't work or
b) I am using it incorrectly

I'm recoding it entirely. It also makes no sense to me that an inner class is necessary in this case, so I'm getting rid of it. If anyone has any ideas on how the error I got could have happened, please let me know.


If the entire code base uses generics, there is no way that would happen; after all, generics were introduced for this very reason. Are you sure that the code base doesn't ditch generics and falls back to raw collections at some point? Have you used a debugger to trace the program flow so as to view the methods which add data to the vector?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.