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.

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?

Posted code not gives base to conclusion. Cast to String? Which part of code want to do it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.