0

メッセージをロードするために GWT で ClientBundle を使用しようとしています。

これが私のコードです:gwt.xml

<?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 を拡張するインターフェース:

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 クラスで画像を使用しようとしています。

ImageResource[] icons = new ImageResource[]{
                Resources.IMPL.blogger(),
                Resources.IMPL.delicious(),
                Resources.IMPL.facebook()
        };

そして、私が得るエラー:

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()問題のようだということです。

4

2 に答える 2

1

以下に示すように相対位置を試してください

@Source("../resources/blogger.png")
ImageResource blogger();
@Source("../resources/delicious.png")
ImageResource delicious();
@Source("../resources/facebook.png")
ImageResource facebook();

プロジェクトの構造

ro/gebs/master
            |
            |__resources
            |          |
            |          |__blogger.png
            |
            |__client
                     |
                     |__StockWatcher.java

- 編集 -

画像が正しい名前と拡張子で正しい場所に配置されていることを確認してください。

于 2014-05-13T08:35:46.993 に答える
0

Resources{module}.gwt.xml のパス エントリを削除します。必要ありません。

<source path='resources'/>  
于 2014-05-13T08:35:58.303 に答える