on 01-05-2007 1:32 PM
Hi,
I have implemented a portal service (NoticeBoardService) and I'm trying to use it from a web dynpro application.
This portal service contains a method which returns an ArrayList of objects (Notice).
For example:
public ArrayList getNotices(..);
When I call this method from a web dynpro application and try to cast elements from
this arraylist I get ClassCastException.
For example:
ArrayList list = service.getNotices();
...
for (int i=0;i<list.size();i++)
{
Notice n = (Notice)list.get(i); //ClassCastException occurs here
}
When I display runtime class of "n", it is displayed correctly.
Maybe somebody has idea what is going on?
Maybe the Notice class must implement some standard interfaces?
I'm stuck with this one..
Btw, When I use String class instead of Notice class everything is working ok.
Regards,
Ladislav
Message was edited by:
Ladislav Pomezny
Hi,
Do a simple check to see what type of objects are contained in the ArrayList.
if(n instanceof Notice){
...
}else if(n instanceof String){
..
}
Obviously if the object is String you cannot cast it to Notice. Check if the getNotices method is really creating Notice objects into ArrayList or String objects.
Hope that helps,
Rajit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for the reply.
I've found a solution to this problem.
It seems that I had some classloader problems. I've fixed some project references and
now its working ok.
I'm posting a working configuration in case somebody has similar problem someday:
1) Notice (java project with Notice.java)
2) NoticeBoard (web dynpro project which uses portal service and casts ArrayList item to Notice class)
project references:
Notice
NoticeBoardService
sharing references for NoticeBoardService
3) NoticeBoardService (portal service project)
project references:
Notice
notice.jar (from Notice project) file in dist/PORTAL-INF/lib/ folder of portal service
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.