GXT 3,网格编译问题

时间:2012-10-22 19:40:07

标签: gwt gxt

我正在尝试运行GXT 3 Grid,但在运行GWT编译表单Eclipse时遇到以下异常:

java.lang.NullPointerException
at com.sencha.gxt.data.rebind.ModelKeyProviderCreator.getObjectType(ModelKeyProviderCreator.java:40)

启动网格并使其可见的代码:

DataProperties dp = GWT.create(DataProperties.class);
List<ColumnConfig<MyGridData, ?>> css = new LinkedList<ColumnConfig<MyGridData, ?>>();
css.add(new ColumnConfig<MyGridData, String>(dp.name(), 200, "Name"));      
css.add(new ColumnConfig<MyGridData, String>(dp.value(), 200, "Value"));

ColumnModel<MyGridData> cm = new ColumnModel<MyGridData>(css);
ListStore<MyGridData> s = new ListStore<MyGridData>(dp.key());
s.add(new MyGridData("name1","value1"));
s.add(new MyGridData("name2","value2"));
s.add(new MyGridData("name3","value3"));
s.add(new MyGridData("name4","value4"));
Grid<MyGridData> g = new Grid<MyGridData>(s, cm);
addToDisplay(g);

网格数据bean:

public class MyGridData{
    private String name;
private String value;

public MyGridData(String name, String value) {
        super();
    this.name = name;
        this.value = value;
}

public void setName(String name) {
    this.name = name;
}

public String getName() {
    return this.name;
}

public void setValue(String value) {
    this.value = value;
}

public String getValue() {
        return this.value;
}

 }

支持DataProperties类:

import com.google.gwt.editor.client.Editor.Path;
import com.sencha.gxt.core.client.ValueProvider;
import com.sencha.gxt.data.shared.ModelKeyProvider;
import com.sencha.gxt.data.shared.PropertyAccess;

public interface DataProperties extends PropertyAccess {

    @Path("name")
ModelKeyProvider key();

ValueProvider<MyGridData, String> name();
ValueProvider<MyGridData, String> value();
}

1 个答案:

答案 0 :(得分:2)

从你的代码:

public interface DataProperties extends PropertyAccess {

  @Path("name")
  ModelKeyProvider key();

  ValueProvider<MyGridData, String> name();
  ValueProvider<MyGridData, String> value();
}

这里有一个错误 - 没有泛型,编译器无法弄清楚你需要什么。您的IDE应该警告您对ProperyAccess和ModelKeyProvider的原始使用。这两个都需要引用MyGridData。试试这个:

public interface DataProperties extends PropertyAccess<MyGridData> {//here

  @Path("name")
  ModelKeyProvider<MyGridData> key();// and here

  ValueProvider<MyGridData, String> name();
  ValueProvider<MyGridData, String> value();
}