GWT DataGrid错误:`com.google.gwt.user.client.ui.IsWidget未定义`附加到`SimplePanel`

时间:2016-03-15 08:13:28

标签: java gwt datagrid

我想在我的项目中使用GWT DataGrid widget。我甚至找到了最简单的解决方案here。很遗憾,我收到了一条错误:Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not defined。我注意到只有当我有这行代码时才会出现这种情况:dataGrid.add(table);其中 dataGrid 变量为:

@UiField
SimplePanel dataGrid;

变量是:

DataGrid<Address> table = new DataGrid<Address>();

以下是来自网络浏览器控制台(Google Chrome)的完整堆栈跟踪:

Tue Mar 15 08:54:41 GMT+100 2016 com.google.gwt.logging.client.LogConfiguration
SEVERE: Exception caught: Exception caught: Exception caught: Exception caught: (ReferenceError) : Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not definedcom.google.gwt.user.client.ui.AttachDetachException: Exception caught: Exception caught: Exception caught: Exception caught: (ReferenceError) : Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not defined
    at Unknown.fillInStackTrace_0_g$(cms-0.js@3:8683)
    at Unknown.Throwable_3_g$(cms-0.js@8:8638)
    at Unknown.Exception_3_g$(cms-0.js@18:8781)
    at Unknown.RuntimeException_3_g$(cms-0.js@18:8822)
    at Unknown.UmbrellaException_3_g$(cms-0.js@25:36781)
    at Unknown.UmbrellaException_5_g$(cms-0.js@26:36842)
    at Unknown.AttachDetachException_1_g$(cms-0.js@26:62116)
    at Unknown.tryCommand_1_g$(cms-0.js@11:62172)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.setParent_2_g$(cms-0.js@12:53295)
    at Unknown.adopt_0_g$(cms-0.js@14:61679)
    at Unknown.add_14_g$(cms-0.js@8:61737)
    at Unknown.add_13_g$(cms-0.js@8:61730)
    at Unknown.add_66_g$(cms-0.js@8:89357)
    at Unknown.add_11_g$(cms-0.js@8:61667)
    at Unknown.add_65_g$(cms-0.js@43:89353)
    at Unknown.setPanelContent_0_g$(cms-0.js@54:127158)
    at Unknown.setInSlot_7_g$(cms-0.js@25:119945)
    at Unknown.setInSlot_1_g$(cms-0.js@25:85174)
    at Unknown.setInSlot_0_g$(cms-0.js@8:85163)
    at Unknown.execute_27_g$(cms-0.js@30:88416)
    at Unknown.$executeScheduled_0_g$(cms-0.js@40:11900)
    at Unknown.runScheduledTasks_0_g$(cms-0.js@9:11622)
    at Unknown.flushPostEventPumpCommands_0_g$(cms-0.js@5:11714)
    at Unknown.execute_5_g$(cms-0.js@22:11853)
    at Unknown.execute_4_g$(cms-0.js@19:11590)
    at Unknown.apply_0_g$(cms-0.js@28:11085)
    at Unknown.entry0_0_g$(cms-0.js@16:11141)
    at Unknown.anonymous(cms-0.js@14:11121)
    at Unknown.callback_0_g$(cms-0.js@45:11641)
Caused by: com.google.gwt.user.client.ui.AttachDetachException: Exception caught: Exception caught: Exception caught: (ReferenceError) : Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not defined
    at Unknown.fillInStackTrace_0_g$(cms-0.js@3:8683)
    at Unknown.Throwable_3_g$(cms-0.js@8:8638)
    at Unknown.Exception_3_g$(cms-0.js@18:8781)
    at Unknown.RuntimeException_3_g$(cms-0.js@18:8822)
    at Unknown.UmbrellaException_3_g$(cms-0.js@25:36781)
    at Unknown.UmbrellaException_5_g$(cms-0.js@26:36842)
    at Unknown.AttachDetachException_1_g$(cms-0.js@26:62116)
    at Unknown.tryCommand_1_g$(cms-0.js@11:62172)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.setParent_2_g$(cms-0.js@12:53295)
    at Unknown.adopt_0_g$(cms-0.js@14:61679)
    at Unknown.add_14_g$(cms-0.js@8:61737)
    at Unknown.add_13_g$(cms-0.js@8:61730)
    at Unknown.add_66_g$(cms-0.js@8:89357)
    at Unknown.add_11_g$(cms-0.js@8:61667)
    at Unknown.add_65_g$(cms-0.js@43:89353)
    at Unknown.setPanelContent_0_g$(cms-0.js@54:127158)
    at Unknown.setInSlot_7_g$(cms-0.js@25:119945)
    at Unknown.setInSlot_1_g$(cms-0.js@25:85174)
    at Unknown.setInSlot_0_g$(cms-0.js@8:85163)
    at Unknown.execute_27_g$(cms-0.js@30:88416)
    at Unknown.$executeScheduled_0_g$(cms-0.js@40:11900)
    at Unknown.runScheduledTasks_0_g$(cms-0.js@9:11622)
    at Unknown.flushPostEventPumpCommands_0_g$(cms-0.js@5:11714)
    at Unknown.execute_5_g$(cms-0.js@22:11853)
    at Unknown.execute_4_g$(cms-0.js@19:11590)
    at Unknown.apply_0_g$(cms-0.js@28:11085)
    at Unknown.entry0_0_g$(cms-0.js@16:11141)
    at Unknown.anonymous(cms-0.js@14:11121)
    at Unknown.callback_0_g$(cms-0.js@45:11641)
Caused by: com.google.gwt.user.client.ui.AttachDetachException: Exception caught: Exception caught: (ReferenceError) : Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not defined
    at Unknown.fillInStackTrace_0_g$(cms-0.js@3:8683)
    at Unknown.Throwable_3_g$(cms-0.js@8:8638)
    at Unknown.Exception_3_g$(cms-0.js@18:8781)
    at Unknown.RuntimeException_3_g$(cms-0.js@18:8822)
    at Unknown.UmbrellaException_3_g$(cms-0.js@25:36781)
    at Unknown.UmbrellaException_5_g$(cms-0.js@26:36842)
    at Unknown.AttachDetachException_1_g$(cms-0.js@26:62116)
    at Unknown.tryCommand_1_g$(cms-0.js@11:62172)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.setParent_2_g$(cms-0.js@12:53295)
    at Unknown.adopt_0_g$(cms-0.js@14:61679)
    at Unknown.add_14_g$(cms-0.js@8:61737)
    at Unknown.add_13_g$(cms-0.js@8:61730)
    at Unknown.add_66_g$(cms-0.js@8:89357)
    at Unknown.add_11_g$(cms-0.js@8:61667)
    at Unknown.add_65_g$(cms-0.js@43:89353)
    at Unknown.setPanelContent_0_g$(cms-0.js@54:127158)
    at Unknown.setInSlot_7_g$(cms-0.js@25:119945)
    at Unknown.setInSlot_1_g$(cms-0.js@25:85174)
    at Unknown.setInSlot_0_g$(cms-0.js@8:85163)
    at Unknown.execute_27_g$(cms-0.js@30:88416)
    at Unknown.$executeScheduled_0_g$(cms-0.js@40:11900)
    at Unknown.runScheduledTasks_0_g$(cms-0.js@9:11622)
    at Unknown.flushPostEventPumpCommands_0_g$(cms-0.js@5:11714)
    at Unknown.execute_5_g$(cms-0.js@22:11853)
    at Unknown.execute_4_g$(cms-0.js@19:11590)
    at Unknown.apply_0_g$(cms-0.js@28:11085)
    at Unknown.entry0_0_g$(cms-0.js@16:11141)
    at Unknown.anonymous(cms-0.js@14:11121)
    at Unknown.callback_0_g$(cms-0.js@45:11641)
Caused by: com.google.gwt.user.client.ui.AttachDetachException: Exception caught: (ReferenceError) : Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not defined
    at Unknown.fillInStackTrace_0_g$(cms-0.js@3:8683)
    at Unknown.Throwable_3_g$(cms-0.js@8:8638)
    at Unknown.Exception_3_g$(cms-0.js@18:8781)
    at Unknown.RuntimeException_3_g$(cms-0.js@18:8822)
    at Unknown.UmbrellaException_3_g$(cms-0.js@25:36781)
    at Unknown.UmbrellaException_5_g$(cms-0.js@26:36842)
    at Unknown.AttachDetachException_1_g$(cms-0.js@26:62116)
    at Unknown.tryCommand_1_g$(cms-0.js@11:62172)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.onAttach_14_g$(cms-0.js@46:67161)
    at Unknown.onAttach_4_g$(cms-0.js@20:53405)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.setParent_2_g$(cms-0.js@12:53295)
    at Unknown.adopt_0_g$(cms-0.js@14:61679)
    at Unknown.add_14_g$(cms-0.js@8:61737)
    at Unknown.add_13_g$(cms-0.js@8:61730)
    at Unknown.add_66_g$(cms-0.js@8:89357)
    at Unknown.add_11_g$(cms-0.js@8:61667)
    at Unknown.add_65_g$(cms-0.js@43:89353)
    at Unknown.setPanelContent_0_g$(cms-0.js@54:127158)
    at Unknown.setInSlot_7_g$(cms-0.js@25:119945)
    at Unknown.setInSlot_1_g$(cms-0.js@25:85174)
    at Unknown.setInSlot_0_g$(cms-0.js@8:85163)
    at Unknown.execute_27_g$(cms-0.js@30:88416)
    at Unknown.$executeScheduled_0_g$(cms-0.js@40:11900)
    at Unknown.runScheduledTasks_0_g$(cms-0.js@9:11622)
    at Unknown.flushPostEventPumpCommands_0_g$(cms-0.js@5:11714)
    at Unknown.execute_5_g$(cms-0.js@22:11853)
    at Unknown.execute_4_g$(cms-0.js@19:11590)
    at Unknown.apply_0_g$(cms-0.js@28:11085)
    at Unknown.entry0_0_g$(cms-0.js@16:11141)
    at Unknown.anonymous(cms-0.js@14:11121)
    at Unknown.callback_0_g$(cms-0.js@45:11641)
Caused by: com.google.gwt.core.client.JavaScriptException: (ReferenceError) : Lcom_google_gwt_user_client_ui_IsWidget_2_classLit_0_g$ is not defined
    at Unknown.doAttachChildren_5_g$(cms-0.js@125:63399)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.onAttach_12_g$(cms-0.js@46:63237)
    at Unknown.onAttach_13_g$(cms-0.js@46:63523)
    at Unknown.execute_9_g$(cms-0.js@10:62200)
    at Unknown.tryCommand_1_g$(cms-0.js@14:62156)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:61692)
    at Unknown.onAttach_2_g$(cms-0.js@8:53199)
    at Unknown.onAttach_14_g$(cms-0.js@46:67161)
    at Unknown.onAttach_4_g$(cms-0.js@20:53405)

这是视图类:

import java.util.Arrays;
import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.DataGrid;
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.SelectionChangeEvent;
import com.google.gwt.view.client.SingleSelectionModel;
import com.gwtplatform.mvp.client.ViewWithUiHandlers;

public class FilesView extends ViewWithUiHandlers<FilesUiHandlers> implements FilesPresenter.MyView {
    interface Binder extends UiBinder<Widget, FilesView> {
    }

    private static FilesViewUiBinder uiBinder = GWT.create(FilesViewUiBinder.class);

    interface FilesViewUiBinder extends UiBinder<Widget, FilesView> {
    }

    @UiField
    SimplePanel dataGrid;

    public FilesView() {
    initWidget(uiBinder.createAndBindUi(this));
    loadTable();
    }

    /**
     * A simple data type that represents an Address.
     */
    private static class Address {
    private final String houseNumber;
    private final String streetName;
    private final String county;
    private final String postCode;
    private final String country;

    public Address(String houseNumber, String streetName, String county, String postCode, String country) {
        this.houseNumber = houseNumber;
        this.streetName = streetName;
        this.county = county;
        this.postCode = postCode;
        this.country = country;
    }
    }

    /*
     * The list of data to display.
     */
    private static final List<Address> ADDRESS = Arrays.asList(new Address("123", "Lloyds Road", "Middlesex", "TE0 6NB", "United Kingdom"), new Address("456", "Oxford Street", "Oxford", "LK9 0CV",
        "United Kingdom"));

    public void loadTable() {
    DataGrid<Address> table = new DataGrid<Address>();
    table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);

    TextColumn<Address> houseNumber = new TextColumn<Address>() {
        @Override
        public String getValue(Address object) {
        return object.houseNumber;
        }
    };
    table.addColumn(houseNumber, "House Number");

    TextColumn<Address> streetName = new TextColumn<Address>() {
        @Override
        public String getValue(Address object) {
        return object.streetName;
        }
    };
    table.addColumn(streetName, "Street Name");

    TextColumn<Address> county = new TextColumn<Address>() {
        @Override
        public String getValue(Address object) {
        return object.county;
        }
    };
    table.addColumn(county, "County");

    TextColumn<Address> postCode = new TextColumn<Address>() {
        @Override
        public String getValue(Address object) {
        return object.postCode;
        }
    };
    table.addColumn(postCode, "Post Code");

    TextColumn<Address> country = new TextColumn<Address>() {
        @Override
        public String getValue(Address object) {
        return object.country;
        }
    };
    table.addColumn(country, "Country");

    // Add a selection model to handle user selection.
    final SingleSelectionModel<Address> selectionModel = new SingleSelectionModel<Address>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
        Address selected = selectionModel.getSelectedObject();
        if (selected != null) {
            Window.alert("You selected: " + selected.houseNumber + " " + selected.streetName + " " + selected.county + " " + selected.postCode + " " + selected.country);
        }
        }
    });
    table.setRowCount(ADDRESS.size(), true);
    table.setRowData(0, ADDRESS);
    table.setWidth("100%");
    // SimpleLayoutPanel slp = new SimpleLayoutPanel();

    dataGrid.add(table);
    // Add it to the root panel.
    // RootLayoutPanel.get().add(slp);
    }

}

和视图绑定视图类:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:m="urn:import:gwt.material.design.client.ui"
    >
    <m:MaterialRow>
        <g:HTMLPanel>
            <h2>Your files</h2>
            <g:SimplePanel ui:field="dataGrid" />
        </g:HTMLPanel>
    </m:MaterialRow>
</ui:UiBinder>

演示者不要做任何特别的事情。

我使用GWT 2.7

请帮忙。

1 个答案:

答案 0 :(得分:0)

这很奇怪,但它应该是:

  1. 清理并安装项目。
  2. 重启超级开发模式