如何解决java中的java.lang.ClassCastException?

时间:2014-01-07 12:38:47

标签: java exception listbox zk zul

我在zk中选择多个复选框时遇到问题。当我为多个数据encrypt/decrypt选择列表框标题复选框时,为java.lang.ClassCastException提供了encrypt/decrypt,当我为selectedFolderInfo选择多个没有列表标题的listcell时,它正常工作。

aftercompose方法中 Set<FolderInfoData> selectedFolderInfo = new HashSet<FolderInfoData>(); 的内部化

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

这是我的代码:

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)

列表框:enter image description here

这是Logcat:

{{1}}

” 有人给我任何建议如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:0)

我现在就把selectedFolderInfo的工作投好了。

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