Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Getting ClassCastException after GWT upgrade

    Below is the sample method i am writing to get selected items and using the values in view calss

    public List<TestClass> getSelectedElements(){
    List<TestClass> _items = new ArrayList<TestClass>();
    if(isShowSelectedControl ){
    ListGridRecord[] items = selectedItems.getRecords();
    if(items!= null)
    for (ListGridRecord item : items) {
    TestClass _item = new TestClass();
    _item.setParentId(item.getAttribute("pId"));
    _item.setParents((ArrayList<MyClass>)item.getAttributeAsObject("parent"));
    _items.add(_item);
    }
    }
    return _items;
    }

    while executing " _item.setParents((ArrayList<MyClass>)item.getAttributeAsObject("parent"));"
    line its giving a java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$ cannot be cast to com.proj.shared.MyClass

    item.getAttributeAsObject will return a java Object which will have the values of type com.google.gwt.core.client.JavaScriptObject

    is there any way i can get the values as an ArrayList<MyClass> or cast it into ArrayList<MyClass>??

    As far as i remember it was working with GWT-2.4.0 & smartgwt-3.0 and it was not giving any casting exception
    with upgrade of GWT-2.6.1 and smartgwt-4.1 this problem occurred and its giving casting exception.

    Please help

    #2
    Figured out the reason for failure, while setting the data to the ListGridRecord i was using setAttribute() and trying read it as an object because which it was giving ClassCastException, used setAttributeAsJavaObject() instead and issue resolved.

    Comment

    Working...
    X