Thursday, August 18, 2011

GWT : compilation error with Map


Problème :

         In your code, you declare Map<Integer, Integer> map = new HashMap<Integer, Integer>
and you have the following error  :

         [ERROR] Line 23: No source code is available for type com.google.gwt.dev.util.collect.HashMap<K,V>; did you forget to inherit a required module?


Solution :

Map collections works with Object.However Object isn't serializable.So to work, you have to pass the following arguments in comments :@gwt.typeArgs <java.lang.Integer,java.lang.Integer>
to define the contents of your map :


public class ChartData implements IsSerializable {

  /**
   * This field is a Map that must always contain Strings as its keys and
   * values.
   * 
   * @gwt.typeArgs <java.lang.Integer,java.lang.Integer>
   */
  public Map data;
  
  public ChartData() {
  }
}


Then you can use your Map like that :

CharData charData = new CharData();
charData.data.put(12,13);

Ref :

No comments:

Post a Comment