It's all about the answers!

Ask a question

getting java class cast exception.


lakshmi jyothsna (37118) | asked Feb 01 '17, 6:54 a.m.
edited Feb 01 '17, 7:42 a.m. by Ralph Schoon (63.5k33646)

 I want to get the owner ID of the work item. I used the below snippet to get the ID . But i end up with an error java class cast exception,


    IContributor contributor = (IContributor) teamRepository.itemManager() 
                .fetchCompleteItem(handle, IItemManager.DEFAULT, null); 
        String userID=contributor.getUserId(); 
Please help me how to get Owner ID  from Icontributor handle.

Please any one clarify the difference between Owner and Creator of work item in RTC.

Waiting forward for response...
Thanks in advance,.

3 answers



permanent link
Ralph Schoon (63.5k33646) | answered Feb 01 '17, 7:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Carefully follow this post and set up your environment for debugging the API: Understanding and Using the RTC Java Client API. In addiion that code does not help if it is unclear where the exception happens and what the handle is.


Comments
lakshmi jyothsna commented Feb 01 '17, 9:45 a.m. | edited Feb 01 '17, 9:55 a.m.

 Hi Ralph,


Thanks for your response. We are using that Icontributor handle only. Getowner gives the contributor handle , that we are unable to resolve. we are getting the exception that : workitem is of type model not of type api.common. Kindly help us how to retrive the owner id of work item from contributor handle.

please help us.

thanks.


permanent link
Ralph Schoon (63.5k33646) | answered Feb 01 '17, 9:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Feb 01 '17, 9:55 a.m.

There is no work item in your code above. You expect anyone to comment on code you don't show in the question?



Carefully follow this post and set up your environment for debugging the API: Understanding and Using the RTC Java Client API. In addiion that code does not help if it is unclear where the exception happens and what the handle is.
See https://rsjazz.wordpress.com/2014/05/26/only-owner-can-close-workitem-advisor/ to understand how to get the owner. IContributorHandle owner = workItem.getOwner();


permanent link
kevin kat (11) | answered Jul 12 '21, 1:23 a.m.

 The exaception  thrown to indicate that your code has attempted to cast an object to a subclass of which it is not an instance. This means that ClassCastException occurs when you try to cast an instance of an Object to a type that it is not. Type Casting only works when the casted object follows an is a relationship to the type you are trying to cast to.


It is good practice to guard any explicit casts with an instanceof check first:

if (myApple instanceof Fruit) {
  Fruit myFruit = (Fruit)myApple;
}

When will be ClassCastException is thrown:
  • When you try to cast an object of Parent class to its Child class type, this exception will be thrown.
  • When you try to cast an object of one class into another class type that has not extended the other class or they don't have any relationship between them.


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.