Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Class Cast Exception and I can't figure it out

Thread view: 
da_rod_father - 12 Feb 2006 04:33 GMT
I am getting an exception at runtime when I try to cast a class of type
that i created to an ArrayList:

<%  ArrayList secs = help.getList();
          if (secs != null && secs.size() >0) {
               for ( int i = 0; i < secs.size(); i++) {
    PropertyFileSectionData secName = (PropertyFileSectionData)
secs.get(i);
%>

It crashes everytime I try to render this line in a jsp:

        <label><%=secName.getSectionName() %></label></td>

I get a java.lang.ClassCastException: java.lang.String and it complains
that  java.lang.String it is not comparable to my class I created(
PropertyFileSectionData ).  Could anyone point me in the right
direction to debug this?

thx
Ian Mills - 12 Feb 2006 09:37 GMT
> I am getting an exception at runtime when I try to cast a class of type
> that i created to an ArrayList:
[quoted text clipped - 16 lines]
>
> thx

Please provide the source for PropertyFileSectionData, although it would
suggest that the getSectionName method is not returning a String.
da_rod_father - 12 Feb 2006 14:58 GMT
I created an interface with abstract methods.

public interface PropertyFileSectionData
{
   public abstract String getSectionName();
   public abstract void setSectionName(String sectionName);

   public abstract String getSectionComment();
   public abstract void setSectionComment(String sectionComment);

   public abstract PropertyFilePropAndValuePairsData
getPropertyAndValuePairs();
   public abstract void
setPropertyAndValuePairs(PropertyFilePropAndValuePairsData
propAndVauePairs);

}

I also create an implementation class to actually do the work.

public class PropertyFileSectionDataImpl implements
PropertyFileSectionData
{
   protected String _sectionName;
   protected String _sectionComment;
   protected  SPPropertyFilePropAndValuePairsData _propAndValuePairs;

       public PropertyFilePropAndValuePairsData
getPropertyAndValuePairs()  {
       return _propAndValuePairs;
   }
      public void
setPropertyAndValuePairs(PropertyFilePropAndValuePairsData
andValuePairs)   {
       _propAndValuePairs = andValuePairs;
   }
      public String getSectionComment()  {
       return _sectionComment;
   }
      public void setSectionComment(String comment)   {
       _sectionComment = comment;
   }
      public String getSectionName()   {
       return _sectionName;
   }
     public void setSectionName(String name)  {
       _sectionName = name;
   }
}
da_rod_father - 12 Feb 2006 17:51 GMT
I am wondering if I am modeling this wrong?  Are there any good
examples on how to correctly implement interfaces?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.