How to resolve java.lang.ClassCastException in java?

3.3k views Asked by At

I have an issue selecting multiple checkbox in zk. when i selecte listbox header checkbox for multiple data encrypt/decrypt that give me this java.lang.ClassCastException and when i select multiple listcell without list header checkbox for encrypt/decrypt it working fine .

Internalization of selectedFolderInfo in aftercompose method

 Set<FolderInfoData> selectedFolderInfo = new HashSet<FolderInfoData>();

Here's my code:

@Command
@NotifyChange({ "folderInfoList", "selectedFolderInfo" })
public void encryptInfo() {
    if (selectedFolderInfo == null) {
        showError("Please select an info to Encrypt/Decrypt");
        return;
    } else if (selectedFolderInfo != null && selectedFolderInfo.isEmpty()) {
        showError("Please select an info to Encrypt/Decrypt");
        return;
    }
    List<FolderInfoRecord> folderRecord = new ArrayList<FolderInfoRecord>();
    for(FolderInfoData folderInfoData:selectedFolderInfo){
        FolderInfoRecord folderInfoRecord=folderInfoData.getFolderInforecord();
        folderRecord.add(folderInfoRecord);
    }
    try {
        Services.folderService().encryptDecryptFolderInfoRecords(folderType, folderRecord.toArray(new FolderInfoRecord[0]));

    } catch (FolderInfoPermissionDeniedException e) {
        e.printStackTrace();
    } 

Listbox:enter image description here

Here's Logcat:

Jan 07, 2014 5:37:38 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1359
SEVERE: >>java.lang.ClassCastException: java.lang.String cannot be cast to com.csdcsystems.amanda.jems.web.viewmodel.FolderInfoEditViewModel$FolderInfoData
>>  at com.csdcsystems.amanda.jems.web.viewmodel.FolderInfoEditViewModel.encryptInfo(FolderInfoEditViewModel.java:752)
>>  at sun.reflect.GeneratedMethodAccessor135.invoke(Unknown Source)
>>  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>  at java.lang.reflect.Method.invoke(Unknown Source)
>>  at org.zkoss.bind.impl.ParamCall.call(ParamCall.java:111)
>>  at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1744)
>>  at org.zkoss.bind.impl.BinderImpl.doCommand(BinderImpl.java:1505)
>>  at org.zkoss.bind.impl.BinderImpl.access$1500(BinderImpl.java:107)
>>  at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent0(BinderImpl.java:1374)
>>  at org.zkoss.bind.impl.BinderImpl$CommandEventListener.onEvent(BinderImpl.java:1326)

' Anyone give me any suggestion how can resolve this issue ?

Thanks

1

There are 1 answers

0
Sitansu On BEST ANSWER

I just cast the selectedFolderInfo its work fine now .

     for (Object obj : selectedFolderInfo) {
        if (obj instanceof FolderInfoData) {
            FolderInfoData folderInfoData = (FolderInfoData) obj;
            FolderInfoRecord folderInfoRecord = folderInfoData.getFolderInforecord();
            folderRecord.add(folderInfoRecord);
            }
              }