Hi,
I am getting a class cast exception.
the getVisibleInSitemap() method returns string.
Here is the code
Can anyone let me know how should I overcome this problem
regards,
Saurabh
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
Welcome to JavaRanch.
The cast is "(LinkVO)". So it seems that not all elements of linksArrayList are, in fact, LinkVO objects. You can check that by "System.out.println(linksArrayList.get(i).getClass().getName())"
If Java had generics from the outset, people would always use generics and this sort of problem would be very unusual. Look at the tutorial link I just quoted.
Saurabh udgirs
Greenhorn
Joined: May 20, 2009
Posts: 4
posted
0
Thanks for your inputs
I had put this,
and this is what I got,
By what, we can get rid of this exception...
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
That looks like nodes from a DOM tree. Where/how are you putting LinkVO objects in that list?
Saurabh udgirs
Greenhorn
Joined: May 20, 2009
Posts: 4
posted
0
Hi,
Its been put in a different class, this is how it happens
and this is where linksArrayList is set
The setsublink array in above snippet is just a setter method which sets the value.
Let me know in case you require some other details.
regards,
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
I can't say I understand what's going on (for instance, what does "LinksList" do, and what does it return), but *somehow* objects other than LinkVO are getting into the list. There can't be that many spots in the code where elements of the list are set or added, right?
Saurabh udgirs
Greenhorn
Joined: May 20, 2009
Posts: 4
posted
0
Hi,
Sorry to have missed that,
LinksList is the same method where the code is extracted from, so it is a recursive method
It returns linksArrayList,
And dont think there is any other way by which this arraylist is getting populated.
Also, surprisingly, I am being told that is code is working perfectly fine on one of my colleagues system, Is it related to some java version then or all the java classes in the workspace needs to be rebuilt...? Perhaps I feel that this issue is a code issue and not environmental,
Whats your call?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
4
posted
0
I think this is no longer a "beginner's" thread. Moving.
I would use System.out.println(linksArrayList.get(i).getClass().getName()); _before_ you insert items into the list, see where those DOM nodes are coming from.