2

我正在尝试运行 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();
}
4

1 回答 1

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();
}
于 2012-10-23T01:42:40.073 回答