首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ClientBundle与图像GWT异常

ClientBundle与图像GWT异常
EN

Stack Overflow用户
提问于 2014-05-13 08:10:59
回答 2查看 280关注 0票数 0

我试图在GWT中使用ClientBundle来加载消息。

这是我的代码: gwt.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='StockWatcher'>
    <!-- Inherit the core Web Toolkit stuff.                        -->
    <inherits name='com.google.gwt.user.User'/>

    <!-- We need the JUnit module in the main module,               -->
    <!-- otherwise eclipse complains (Google plugin bug?)           -->
    <inherits name='com.google.gwt.junit.JUnit'/>

    <!-- Inherit the default GWT style sheet.  You can change       -->
    <!-- the theme of your GWT application by uncommenting          -->
    <!-- any one of the following lines.                            -->
    <inherits name='com.google.gwt.user.theme.standard.Standard'/>
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->

    <!-- Other module inherits                                      -->

    <!-- Specify the app entry point class.                         -->
    <entry-point class='ro.gebs.master.client.StockWatcher'/>

    <!-- Specify the paths for translatable code                    -->
    <source path='client'/>
    <source path='shared'/>
    <source path='resources'/>

</module>

扩展ClientBundle的接口:

代码语言:javascript
复制
public interface Resources extends ClientBundle {
    Resources IMPL = (Resources) GWT.create(Resources.class);

    @Source("ro/gebs/master/resources/blogger.png")
    ImageResource blogger();
    @Source("ro/gebs/master/resources/delicious.png")
    ImageResource delicious();
    @Source("ro/gebs/master/resources/facebook.png")
    ImageResource facebook();
}

在这里,我尝试使用我的EntryPoint类中的图像:

代码语言:javascript
复制
ImageResource[] icons = new ImageResource[]{
                Resources.IMPL.blogger(),
                Resources.IMPL.delicious(),
                Resources.IMPL.facebook()
        };

我所犯的错误是:

代码语言:javascript
复制
Exception while loading module ro.gebs.master.client.StockWatcher. See Development Mode for details.

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:411)
    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:744)
Caused by: java.lang.ExceptionInInitializerError
    at ro.gebs.master.client.StockWatcher.onModuleLoad(StockWatcher.java:24)
    ... 9 more
Caused by: java.lang.RuntimeException: Deferred binding failed for 'ro.gebs.master.client.Resources' (did you forget to inherit a required module?)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
    at com.google.gwt.core.shared.GWT.create(GWT.java:72)
    at com.google.gwt.core.client.GWT.create(GWT.java:86)
    at ro.gebs.master.client.Resources.<clinit>(Resources.java:12)
    ... 10 more
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
    at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:610)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:470)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    ... 13 more

这些图像被放置在一个名为“resources”的包中,但我从这个错误中了解到的是,GWT.create()的行似乎是问题所在。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-13 08:35:46

尝试如下所示的相对位置

代码语言:javascript
复制
@Source("../resources/blogger.png")
ImageResource blogger();
@Source("../resources/delicious.png")
ImageResource delicious();
@Source("../resources/facebook.png")
ImageResource facebook();

项目结构

代码语言:javascript
复制
ro/gebs/master
            |
            |__resources
            |          |
            |          |__blogger.png
            |
            |__client
                     |
                     |__StockWatcher.java

-编辑--

确保图像放置在正确的位置下,并具有正确的名称和扩展名.

票数 1
EN

Stack Overflow用户

发布于 2014-05-13 08:35:58

删除{模块}.gwt.xml中的.gwt.xml路径条目。这不需要。

代码语言:javascript
复制
<source path='resources'/>  
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23625921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档