Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

getting java class cast exception.

 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,.

0 votes



3 answers

Permanent link

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.

0 votes

Comments

 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

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();

0 votes


Permanent link

 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.


0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 416
× 170

Question asked: Feb 01 '17, 6:54 a.m.

Question was seen: 3,562 times

Last updated: Jul 12 '21, 1:23 a.m.

Confirmation Cancel Confirm