Wednesday, March 30, 2016

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

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment