GWT CssResource抛出NPE

时间:2012-03-27 05:43:47

标签: gwt

我在使用CssResource时遇到了奇怪的NPE。 我在我的css文件中定义了以下两个css类:

.mainPanelStyle
{
    height: 250px;
    width: 250px;
    background-color: gray;
    cursor: pointer;
}

.titleLabelStyle
{
    font-size: 14px;
    font-family: Segoe UI Semibold;
    color: white;
}

然后,我将界面定义为:

public interface HomePanelCssResource
        extends CssResource
    {
        String mainPanelStyle();

        String titleLabelStyle();
    }

并在ClientBundle类中添加了一个条目:

@Source( "com/myapp/homePanel/css/homePanelDefault.css" )
    HomePanelCssResource getHomePanelStyle();

当我在类文件中使用此CSS资源时,调用cssResource.mainPanelStyle()可以正常工作。但是调用cssResource.titleLabelStyle()会引发NPE。它说“你忘了添加所需的依赖吗?”。

我不知道出了什么问题。你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:3)

我不知道你的错误来自哪里,但这可能对你有帮助......

这就是我定义和访问CssResource的方式:

我的主要课程: 它定义了客户端包和Cssresource名称。

interface MyClientBundler extends ClientBundle {

    public static final MyClientBundler INSTANCE =  GWT.create(MyClientBundler.class);

    //my.css and the whole packege path are allowed
    @Source("stefank/client/my.css")
    public MyResources css();
}

interface MyResources extends CssResource {
    String test();
}


public void onModuleLoad() {
    Label l = new Label("Resource Test");

    MyClientBundler.INSTANCE.css().ensureInjected(); //importaten, else the resource might not be loaded jet

    l.addStyleName(MyClientBundler.INSTANCE.css().test());

    RootPanel.get().add(l);
}

我的css资源(与主类相同的包装内容):

.test {
    background-color: blue;
    height: 50px;
    width: 100px;
}

这使我的标签具有正确的尺寸和正确的背景颜色。

链接: CssResource

相关问题