GWT - 加载入口点时出错

时间:2014-04-24 11:23:54

标签: java gwt gwt-elemental

我正在尝试在GWT 2.6中运行我的应用程序。该项目是使用Elemental(library gwt-elemental)的Webcam示例。我使用的所有源代码,我找到了这个例子:https://code.google.com/p/elemental-getusermedia-demo/source/browse/#svn%2Ftrunk%2FElementalGetUserMediaDemo

当我运行我的应用时,会显示以下错误,但我无法找到该问题的位置。

消息:

 08:08:57.756 [ERROR] [elementalgetusermediademo] Unable to load module entry point class com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo (see associated exception for details)

java.lang.RuntimeException: Deferred binding failed for 'com.google.gwt.user.client.impl.DOMImpl' (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 com.google.gwt.user.client.DOM.<clinit>(DOM.java:64)
    at com.google.gwt.user.client.ui.FlowPanel.<init>(FlowPanel.java:34)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo$ImagesStrip.<init>(ElementalGetUserMediaDemo.java:281)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo.onModuleLoad(ElementalGetUserMediaDemo.java:65)
    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: com.google.gwt.dev.jjs.InternalCompilerException: Unexpected error during visit.
    at com.google.gwt.dev.js.ast.JsVisitor.translateException(JsVisitor.java:483)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:470)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:835)
    at com.google.gwt.dev.js.ast.JsVars$JsVar.traverse(JsVars.java:61)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:848)
    at com.google.gwt.dev.js.ast.JsVars.traverse(JsVars.java:101)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.js.JsToStringGenerationVisitor.printJsBlock(JsToStringGenerationVisitor.java:907)
    at com.google.gwt.dev.js.JsSourceGenerationVisitor.visit(JsSourceGenerationVisitor.java:59)
    at com.google.gwt.dev.js.ast.JsBlock.traverse(JsBlock.java:47)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.shell.Jsni.generateJavaScriptForHostedMode(Jsni.java:253)
    at com.google.gwt.dev.shell.Jsni.getJavaScriptForHostedMode(Jsni.java:241)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.createNativeMethods(ModuleSpaceOOPHM.java:52)
    at com.google.gwt.dev.shell.CompilingClassLoader.injectJsniMethods(CompilingClassLoader.java:1379)
    at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1149)
    at com.google.gwt.dev.shell.CompilingClassLoader.loadClass(CompilingClassLoader.java:1194)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:670)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:473)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    at com.google.gwt.core.shared.GWT.create(GWT.java:72)
    at com.google.gwt.core.client.GWT.create(GWT.java:86)
    at com.google.gwt.user.client.DOM.<clinit>(DOM.java:64)
    at com.google.gwt.user.client.ui.FlowPanel.<init>(FlowPanel.java:34)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo$ImagesStrip.<init>(ElementalGetUserMediaDemo.java:281)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo.onModuleLoad(ElementalGetUserMediaDemo.java:65)
    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.IndexOutOfBoundsException: Index: 11, Size: 11
    at java.util.ArrayList.rangeCheck(ArrayList.java:635)
    at java.util.ArrayList.get(ArrayList.java:411)
    at com.google.gwt.dev.shell.CompilingClassLoader$DispatchClassInfoOracle.getClassInfoByDispId(CompilingClassLoader.java:122)
    at com.google.gwt.dev.shell.CompilingClassLoader.getClassInfoByDispId(CompilingClassLoader.java:1012)
    at com.google.gwt.dev.shell.Jsni$JsSourceGenWithJsniIdentFixup.visit(Jsni.java:109)
    at com.google.gwt.dev.js.ast.JsNameRef.traverse(JsNameRef.java:117)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:835)
    at com.google.gwt.dev.js.ast.JsVars$JsVar.traverse(JsVars.java:61)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.js.JsToStringGenerationVisitor.visit(JsToStringGenerationVisitor.java:848)
    at com.google.gwt.dev.js.ast.JsVars.traverse(JsVars.java:101)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.js.JsToStringGenerationVisitor.printJsBlock(JsToStringGenerationVisitor.java:907)
    at com.google.gwt.dev.js.JsSourceGenerationVisitor.visit(JsSourceGenerationVisitor.java:59)
    at com.google.gwt.dev.js.ast.JsBlock.traverse(JsBlock.java:47)
    at com.google.gwt.dev.js.ast.JsVisitor.doTraverse(JsVisitor.java:468)
    at com.google.gwt.dev.js.ast.JsVisitor.doAccept(JsVisitor.java:445)
    at com.google.gwt.dev.js.ast.JsVisitor.accept(JsVisitor.java:109)
    at com.google.gwt.dev.shell.Jsni.generateJavaScriptForHostedMode(Jsni.java:253)
    at com.google.gwt.dev.shell.Jsni.getJavaScriptForHostedMode(Jsni.java:241)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.createNativeMethods(ModuleSpaceOOPHM.java:52)
    at com.google.gwt.dev.shell.CompilingClassLoader.injectJsniMethods(CompilingClassLoader.java:1379)
    at com.google.gwt.dev.shell.CompilingClassLoader.findClass(CompilingClassLoader.java:1149)
    at com.google.gwt.dev.shell.CompilingClassLoader.loadClass(CompilingClassLoader.java:1194)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:670)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:473)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    at com.google.gwt.core.shared.GWT.create(GWT.java:72)
    at com.google.gwt.core.client.GWT.create(GWT.java:86)
    at com.google.gwt.user.client.DOM.<clinit>(DOM.java:64)
    at com.google.gwt.user.client.ui.FlowPanel.<init>(FlowPanel.java:34)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo$ImagesStrip.<init>(ElementalGetUserMediaDemo.java:281)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo.onModuleLoad(ElementalGetUserMediaDemo.java:65)
    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)

我的入门点中有两个错误。

   at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo$ImagesStrip.<init>(ElementalGetUserMediaDemo.java:281)
    at com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo.onModuleLoad(ElementalGetUserMediaDemo.java:65)

我的课程入学点:

    package com.jooink.experiments.elementalgetusermedia.client;

import java.util.ArrayList;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.jooink.experiments.elementalgetusermedia.client.ElementalUtils.UserMediaCallback;

import elemental.client.Browser;
import elemental.events.Event;
import elemental.events.EventListener;
import elemental.html.CanvasElement;
import elemental.html.CanvasRenderingContext2D;
import elemental.html.VideoElement;

/**
 * trivial sample of video/canvas & getUSerMedia
 */
public class ElementalGetUserMediaDemo implements EntryPoint {




    //caching a canvas
    private CanvasElement canvas = Browser.getDocument().createCanvasElement();

    private ImagesStrip images;

    private static final int tiles_w = 160;
    private static final int tiles_h = 120;



    @Override
    public void onModuleLoad() {



        final UserMediaHolder userMediaHolder = new UserMediaHolder();




        int h = Window.getClientHeight();
        int w = Window.getClientWidth();

        int Nx = w/160;
        int Ny = h/120;

        images = new ImagesStrip(Nx*Ny, tiles_w + "px", tiles_h + "px");



        RootLayoutPanel.get().add(images);


        Button cam = new Button("Capture My Cam");
        cam.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                if(!userMediaHolder.getUserMedia(userMediaCallback)) 
                    Window.alert("FAIL: your browser \""+ Window.Navigator.getUserAgent()+"\" does not support WebRTC's getUserMedia :(");
            };
        });

        PopupPanel pp = new PopupPanel(false, true);
        pp.add(cam);
        pp.center();
        pp.show();




    }




    private  String makePicture(VideoElement videoElement, CanvasElement canvasElement) {
        canvasElement.setWidth( videoElement.getVideoWidth());
        canvasElement.setHeight( videoElement.getVideoHeight());
        elemental.html.CanvasRenderingContext2D ctx = (CanvasRenderingContext2D) canvasElement.getContext("2d");
        ctx.drawImage(videoElement, 0, 0);
        return canvasElement.toDataURL("image/png");
    }



    private  final UserMediaCallback userMediaCallback = new UserMediaCallback()  {

        public void onSuccess(String s) {   

            final PopupPanel popupPanel = new PopupPanel(false,true);

            final ElementalVideoWidget video = new ElementalVideoWidget();

            video.getVideoElement().setSrc(s);
            video.getVideoElement().play();


            popupPanel.setWidget(new HTML("Waiting for video to become available"));
            popupPanel.center();
            popupPanel.show();


            //finalize the ui when the video is available
            video.getVideoElement().addEventListener("loadedmetadata", new EventListener() {
                @Override
                public void handleEvent(Event evt) {
                    int w = video.getVideoElement().getVideoWidth();
                    int h = video.getVideoElement().getVideoHeight();

                    video.setSize(w+"px", h+"px");

                    final VerticalPanel vp = new VerticalPanel();
                    vp.add(video);

                    final HorizontalPanel hp = new HorizontalPanel();
                    Anchor click = new Anchor("make a picture");
                    click.addClickHandler( new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {
                            String data = makePicture(video.getVideoElement(), canvas);



                            Anchor done = new Anchor("done");
                            done.getElement().getStyle().setColor("red");
                            done.addClickHandler(new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent event) {
                                    popupPanel.hide();
                                }
                            });

                            vp.clear();
                            vp.add(new Image(data));                            
                            vp.add(hp);
                            hp.clear();
                            hp.add(done);
                            hp.setCellHorizontalAlignment(done, HasHorizontalAlignment.ALIGN_CENTER);
                        }
                    });

                    Anchor close = new Anchor("close");
                    close.addClickHandler(new ClickHandler() {  
                        @Override
                        public void onClick(ClickEvent event) {
                            popupPanel.hide();
                        }
                    });

                    Anchor timely_circular = new Anchor("stream (circular)");
                    timely_circular.addClickHandler( new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {

                            final Timer timer = new Timer() {
                                @Override
                                public void run() {
                                    String data = makePicture(video.getVideoElement(),canvas);
                                    images.push_circular(data);
                                }
                            };

                            Anchor stop = new Anchor("stop");
                            stop.getElement().getStyle().setColor("red");
                            stop.addClickHandler(new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent event) {
                                    timer.cancel();
                                    popupPanel.hide();
                                }
                            });

                            hp.clear();
                            hp.add(stop);
                            hp.setCellHorizontalAlignment(stop, HasHorizontalAlignment.ALIGN_CENTER);
                            video.getVideoElement().setWidth(tiles_w);
                            video.getVideoElement().setHeight(tiles_h);
                            video.setSize(tiles_w + "px", tiles_h + "px");
                            popupPanel.center();
                            String data = makePicture(video.getVideoElement(),canvas);
                            images.push_circular(data);
                            timer.scheduleRepeating(250);
                        }
                    });

                    Anchor timely_moving = new Anchor("stream (moving)");
                    timely_moving.addClickHandler( new ClickHandler() {
                        @Override
                        public void onClick(ClickEvent event) {

                            final Timer timer = new Timer() {
                                @Override
                                public void run() {
                                    String data = makePicture(video.getVideoElement(),canvas);
                                    images.push_shift(data);
                                }
                            };

                            Anchor stop = new Anchor("stop");
                            stop.getElement().getStyle().setColor("red");
                            stop.addClickHandler(new ClickHandler() {

                                @Override
                                public void onClick(ClickEvent event) {
                                    timer.cancel();
                                    popupPanel.hide();
                                }
                            });

                            hp.clear();
                            hp.add(stop);
                            hp.setCellHorizontalAlignment(stop, HasHorizontalAlignment.ALIGN_CENTER);
                            video.getVideoElement().setWidth(tiles_w);
                            video.getVideoElement().setHeight(tiles_h);
                            video.setSize(tiles_w + "px", tiles_h + "px");
                            popupPanel.center();
                            String data = makePicture(video.getVideoElement(),canvas);
                            images.push_shift(data);
                            timer.scheduleRepeating(250);
                        }
                    });


                    hp.setWidth("100%");

                    hp.add(click);
                    hp.setCellHorizontalAlignment(click, HasHorizontalAlignment.ALIGN_LEFT);
                    hp.setCellWidth(click, "25%");

                    hp.add(timely_circular);
                    hp.setCellHorizontalAlignment(timely_circular, HasHorizontalAlignment.ALIGN_CENTER);
                    hp.setCellWidth(timely_circular, "25%");

                    hp.add(timely_moving);
                    hp.setCellHorizontalAlignment(timely_moving, HasHorizontalAlignment.ALIGN_CENTER);
                    hp.setCellWidth(timely_moving, "25%");

                    hp.add(close);
                    hp.setCellHorizontalAlignment(close, HasHorizontalAlignment.ALIGN_RIGHT);
                    hp.setCellWidth(close, "25%");

                    vp.add(hp);

                    popupPanel.setWidget(vp);
                    popupPanel.center();                    
                }
            });



        }


        public void onFail() {
            Window.alert("FAIL: please let me access your camera");
        }
    };



    public class ImagesStrip implements IsWidget {
        private FlowPanel panel = new FlowPanel();
        private ArrayList<Image> images = new ArrayList<Image>();
        @Override
        public Widget asWidget() {
            return panel;
        }

        private int current = 0;
        private int len;
        private String width;
        private String height;
        public ImagesStrip(int len, String w, String h) {
            this.len = len;
            this.width = w;
            this.height = h;
        }


        public void push_circular(String url) {
            int pos = current%len;

            if(images.size() <= pos) {
                Image img = new Image();
                img.setSize(width, height);
                panel.add(img);
                images.add(img);
            }
            images.get(pos).setUrl(url);
            current++;
        }

        public void push_shift(String url) {

            int pos = current%len;

            if(images.size() <= pos) {
                Image img = new Image();
                img.setSize(width, height);
                panel.add(img);
                images.add(img);
            } 
            if(current > len) {
                Image img = images.get(pos);
                panel.remove(img);
                panel.add(img);
            }
            images.get(pos).setUrl(url);


            current++;
        }


    }


}

有错误的行:

        private FlowPanel panel = new FlowPanel();

        images = new ImagesStrip(Nx*Ny, tiles_w + "px", tiles_h + "px");

我的gwt.xml

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.6.0//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.6.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='elementalgetusermediademo'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>

  <inherits name="elemental.Elemental"/>


  <!-- 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.clean.Clean'/>
  <!-- <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='com.jooink.experiments.elementalgetusermedia.client.ElementalGetUserMediaDemo'/>

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

</module>

我的论点:

-remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -startupUrl ElementalGetUserMediaDemo.html -logLevel INFO -codeServerPort 9997 -port 8888 -war C:\GWTDev\ElementalGetUserMediaDemo\war com.jooink.experiments.elementalgetusermedia.ElementalGetUserMediaDemo

有人可以帮忙吗?谢谢你的关注。

1 个答案:

答案 0 :(得分:0)

根本原因是

 Caused by: java.lang.IndexOutOfBoundsException: Index: 11, Size: 11

你有

private ArrayList<Image> images = new ArrayList<Image>();

images.get(11)会导致上述错误。


检查代码中的所有images.get(pos)来电。在调用此方法之前进行大小检查,如下所示。

        if(pos >= 0 && pos < images.size()){
            images.get(pos);
        }