cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using portal service method which returns collection in web dynpro

former_member188498
Active Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

former_member188498
Active Participant
0 Kudos

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

Answers (0)