Re: removing error



Thomas Weidenfeller wrote:
ste1986 wrote:

I have the following method to remove a String from an ArrayList. when I
try to run it I get a ClassCastException error. I have looked at lots of
examples of similar methods and I cant understand why this happens because
it looks right to me.


public void removePerson(String name)
   {
       Iterator it = person.iterator();
       while (it.hasNext())
       {
            Volunteer volunteer = (Volunteer) it.next();
            if (volunteer.withPerson = true)
       {
            System.out.println ("Sorry that person is currently with a
volunteer");
            return;
       }
            else
            person.remove (name);
       }
   }


It is impossible to say what you are doing wrong. Would you please stop posting random snippets, but short(!), complete(!), real code(!)? Where does "person" come from in that code? Also, AT WHICH LINE DOES THE EXCEPTION HAPPEN? We don't operate a psychic hotline here. Provide the complete error message as given by the compiler. Don't type it in, copy-and-paste it. Relate it to the source code.

Also, people expect that you do some work on your own. We are not your remote debuggers. If you look at the error message you will see that it contains a line number and file name and lists the type which couldn't be casted. You did look at the error message, didn't you? Look at the mentioned source code line. It is in your source code (the code we probably don't have).

/Thomas
Thank you Thomas - I couldn't have put it better.

Mark
.



Relevant Pages

  • Re: removing error
    ... I have looked at lots of examples of similar methods and I cant understand why this happens because it looks right to me. ... Volunteer volunteer = it.next; ... If you look at the error message you will see that it ... It is in your source code (the code we ...
    (comp.lang.java.help)
  • Re: I dotn understand this error
    ... i llok at line 43 but cant un derstand what the problem. ... It means the offending line isn't in the source code. ... nothing more can be concluded from the error message. ...
    (comp.lang.perl.misc)
  • RE: The definition of the object is hidden
    ... "Preparing files ... Does that mean partial source code is not included in the project files? ... #Improper error message: "The definition of the object is hidden" ... Visual Studio 2008 web project doesn't have ...
    (microsoft.public.dotnet.general)
  • Re: Access MySQL
    ... You are making posts all over the place. ... How are people here who volunteer ... at least give some info as to what your error message is, ...
    (microsoft.public.access.formscoding)
  • Re: Changing default print setting in PowerPoint
    ... I'm getting the same error message. ... help if He'd care to share source code. ... >> Set the security to low, reinstalled it, still doesn't work. ...
    (microsoft.public.powerpoint)