2

我想学习GWT的lazypanel的实用性。我想使用 Uibinder 来使用它。我已经编写了如下代码。我想将惰性面板用于 tablayoutpanel。

XML 文件

<!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:d="urn:import:com.google.gwt.dom.client"
    xmlns:lazy="urn:import:abc.client">

<g:HTMLPanel>
    <lazy:Lazy1></lazy:Lazy1>
</g:HTMLPanel>



</ui:UiBinder>

这是关联的 java 文件。Lazy1.java

package abc.client;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LazyPanel;
import com.google.gwt.user.client.ui.Widget;

public class Lazy1 extends LazyPanel{

    Label label = new Label("Mani");

    @Override
    protected Widget createWidget() {
        return label;
    }
}

我收到如下异常和错误:-

13:00:08.222 [ERROR] [abc] Generator 'com.google.gwt.uibinder.rebind.UiBinderGenerator' threw an exception while rebinding 'abc.client.AbcUI.abcUIUiBinder'

java.lang.NullPointerException: null
    at com.google.gwt.uibinder.elementparsers.LazyPanelParser.parse(LazyPanelParser.java:40)
    at com.google.gwt.uibinder.rebind.UiBinderWriter.parseElementToField(UiBinderWriter.java:934)
    at com.google.gwt.uibinder.elementparsers.WidgetInterpreter.interpretElement(WidgetInterpreter.java:88)
    at com.google.gwt.uibinder.elementparsers.WidgetInterpreter.interpretElement(WidgetInterpreter.java:34)
    at com.google.gwt.uibinder.elementparsers.InterpreterPipe.interpretElement(InterpreterPipe.java:58)
    at com.google.gwt.uibinder.rebind.GetInnerHtmlVisitor.visitElement(GetInnerHtmlVisitor.java:45)
    at com.google.gwt.uibinder.rebind.ChildWalker.accept(ChildWalker.java:48)
    at com.google.gwt.uibinder.rebind.GetInnerHtmlVisitor.getEscapedInnerHtml(GetInnerHtmlVisitor.java:33)
    at com.google.gwt.uibinder.rebind.XMLElement.consumeInnerHtml(XMLElement.java:391)
    at com.google.gwt.uibinder.rebind.XMLElement.consumeInnerHtml(XMLElement.java:403)
    at com.google.gwt.uibinder.elementparsers.HTMLPanelParser.parse(HTMLPanelParser.java:57)
    at com.google.gwt.uibinder.rebind.UiBinderWriter.parseElementToField(UiBinderWriter.java:934)
    at com.google.gwt.uibinder.rebind.UiBinderParser.parse(UiBinderParser.java:146)
    at com.google.gwt.uibinder.rebind.UiBinderWriter.parseDocumentElement(UiBinderWriter.java:1368)
    at com.google.gwt.uibinder.rebind.UiBinderWriter.parseDocument(UiBinderWriter.java:1073)
    at com.google.gwt.uibinder.rebind.UiBinderGenerator.generateOnce(UiBinderGenerator.java:177)
    at com.google.gwt.uibinder.rebind.UiBinderGenerator.generate(UiBinderGenerator.java:129)
    at com.google.gwt.core.ext.IncrementalGenerator.generateNonIncrementally(IncrementalGenerator.java:40)
    at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:657)
    at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
    at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:79)
    at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:276)
    at com.google.gwt.dev.shell.ShellModuleSpaceHost.rebind(ShellModuleSpaceHost.java:141)
    at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:465)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    at com.google.gwt.core.shared.GWT.create(GWT.java:57)
    at com.google.gwt.core.client.GWT.create(GWT.java:85)
    at abc.client.AbcUI.&lt;clinit&gt;(AbcUI.java:12)
    at abc.client.ABC.onModuleLoad(ABC.java:10)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Thread.java:662)

ABC.java

package abc.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;


public class ABC implements EntryPoint {

    public void onModuleLoad() {
        RootPanel.get().add(new AbcUI());
    }
}

AbcUi.java

package abc.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.LazyPanel;

public class AbcUI extends Composite {

    interface abcUIUiBinder extends UiBinder<HTMLPanel, AbcUI> {}
    private static abcUIUiBinder uiBinder = GWT.create(abcUIUiBinder.class);


    public AbcUI() {
        initWidget(uiBinder.createAndBindUi(this));
    }
}
4

1 回答 1

2

据此,如果您没有 LazyPanel 的 @UiField 注释,则会出现此错误。所以我会尝试以下方法:

对于 UiBinder XML 文件:

<!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:d="urn:import:com.google.gwt.dom.client"
    xmlns:lazy="urn:import:abc.client">

    <g:HTMLPanel>
        <lazy:Lazy1 ui:field="myLazy1"/>
    </g:HTMLPanel>

</ui:UiBinder>

对于您的 AbcUi.java 文件:

package abc.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.LazyPanel;

public class AbcUI extends Composite {

    interface abcUIUiBinder extends UiBinder<HTMLPanel, AbcUI> {}
    private static abcUIUiBinder uiBinder = GWT.create(abcUIUiBinder.class);

    @UiField
    Lazy1 myLazy1;

    public AbcUI() {
        initWidget(uiBinder.createAndBindUi(this));
    }
}
于 2013-03-13T12:44:34.883 回答