AnsweredAssumed Answered

ClassCastException

Question asked by sza on Dec 24, 2014
Hi,
I have a problem when I want to get the value of a variable "ClassCastException".
I initially saved a variable like this:


public void saveOrUpdateDocument(String taskId, VariableListDocument documents)throws ExceptionActiviti {
taskService.setVariableLocal(taskId, "DOCUMENT" , documents);
}



Then, if I use the following method (no ClassCastException)

public VariableListDocument getDocuments(String taskId){
   VariableListDocument var = (VariableListDocument) taskService.getVariableLocal(taskId, "DOCUMENT"  );
         return var;   
}


But, I would like to retrieve all the variables that the name "DOCUMENT" for a processInstance but it does not work:



public List< VariableListDocument > listDocuments(String processInstanceId){            
      List<HistoricVariableInstance> result = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("DOCUMENT").list();
      if(result == null || result.isEmpty()){
         return null;
      }
      
      List< VariableListDocument > listDoc = new ArrayList<Document>();
      for(HistoricVariableInstance h :  result){         
         VariableListDocument value = (VariableListDocument )h.getValue();
listDoc.add(value);
      }
      
      return listDoc;
   }


I have two results in my list "result" but but I have the error :

Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to be.nsi.bpm.dto.VariableListDocument

Why ????

Thanks, and sorry for my English I speak French ^^

Outcomes