使用智能gwt 3.0进行问题,对展示样本进行微小更改

时间:2012-03-08 12:46:04

标签: smartgwt gwt2

我正在使用Smart GWT 3.0-特别是我正在使用使用绘图类的旋转样本。

我已经更改了绘制的三角形,而是希望在其位置显示图像 - 我希望此图像的旋转方式与用户单击滑块时旋转其他形状的方式相同(如展示中所示)< / p>

修改代码并保存后,eclipse中没有显示错误。

我更改了三角形形状代码并将其替换为以下内容 -

           DrawImage drawImg= new DrawImage();
           drawImg.setSrc("other/earth.png");
           drawImg.setDrawPane(drawPane);  
           drawImg.setLeft(100);
           drawImg.setHeight(100);
           drawImg.draw();

但是,当我运行GWT Dev模式并尝试查看包含图纸的html页面时,会显示“Uncaught Exception”错误。

以下是我在Google Chrome浏览器无法运行时遇到的错误 -

onModuleLoad() threw an exception
Exception while loading module com.arvindikchari.bspinner.client.Spinner. See Development Mode for details.

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
at     
com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at 

     com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot call method 'create' of undefined
at     
  com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at 
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.smartgwt.client.widgets.drawing.DrawPane.create(DrawPane.java)
at com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj(BaseWidget.java:361)
at com.smartgwt.client.widgets.layout.Layout.addMember(Layout.java:1153)
at com.arvindikchari.bspinner.client.Spinner.onModuleLoad(Spinner.java:244)
... 9 more

UPDATE -

在onModuleLoad的第244行发生错误 - 此行的代码如下所示 -

layout.addMember(drawPane);

由于onModuleLoad的代码而发生错误 - 现在在下面给出了整个代码 -

 public void onModuleLoad() {  
        drawPane = new DrawPane();  
        drawPane.setHeight(450);  
        drawPane.setWidth(700);  
        drawPane.setLeft(25);  
        drawPane.setShowEdges(true);  
        drawPane.setEdgeSize(4);  
        drawPane.setBackgroundColor("papayawhip");  
        drawPane.setOverflow(Overflow.HIDDEN);  
        drawPane.setCursor(Cursor.AUTO);  

        drawPane.addDrawHandler(new DrawHandler() {  

        @Override  
        public void onDraw(DrawEvent event) {  

            DrawPane drawPane = (DrawPane) event.getSource();  

            DrawLabel imglabel= new DrawLabel();


           DrawImage drawImg= new DrawImage();
           drawImg.setSrc("other/earth.png");
           drawImg.setDrawPane(drawPane);  
           drawImg.setLeft(100);
           drawImg.setHeight(100);
           drawImg.draw();


            DrawLabel curveLabel = new DrawLabel();  
            curveLabel.setDrawPane(drawPane);  
            curveLabel.setLeft(200);  
            curveLabel.setTop(175);  
            curveLabel.setContents("Curve");  
            curveLabel.draw();  

            DrawCurve drawCurve = new DrawCurve();  
            drawCurve.setDrawPane(drawPane);  
            drawCurve.setStartPoint(new Point(200,50));  
            drawCurve.setEndPoint(new Point(300,150));  
            drawCurve.setControlPoint1(new Point(250,0));  
            drawCurve.setControlPoint2(new Point(250,200));  
            drawCurve.draw();  

            DrawLabel linePathLabel = new DrawLabel();  
            linePathLabel.setDrawPane(drawPane);  
            linePathLabel.setLeft(350);  
            linePathLabel.setTop(175);  
            linePathLabel.setContents("Line Path");  
            linePathLabel.draw();  

            DrawLinePath drawLinePath = new DrawLinePath();  
            drawLinePath.setDrawPane(drawPane);  
            drawLinePath.setStartPoint(new Point(350,50));  
            drawLinePath.setEndPoint(new Point(450,150));  
            drawLinePath.draw();  

            DrawLabel pathLabel = new DrawLabel();  
            pathLabel.setDrawPane(drawPane);  
            pathLabel.setLeft(500);  
            pathLabel.setTop(175);  
            pathLabel.setContents("Path");  
            pathLabel.draw();  

            DrawPath drawPath = new DrawPath();  
            drawPath.setDrawPane(drawPane);  
            drawPath.setPoints(  
                    new Point(500,50),  
                    new Point(525,50),  
                    new Point(550,75),  
                    new Point(575,75),  
                    new Point(600,75),  
                    new Point(600,125),  
                    new Point(575,125),  
                    new Point(550,125),  
                    new Point(525,150),  
                    new Point(500,150)  
            );  
            drawPath.draw();  

            DrawLabel ovalLabel = new DrawLabel();  
            ovalLabel.setDrawPane(drawPane);  
            ovalLabel.setLeft(50);  
            ovalLabel.setTop(415);  
            ovalLabel.setContents("Oval");  
            ovalLabel.draw();  

            DrawOval drawOval = new DrawOval();  
            drawOval.setDrawPane(drawPane);  
            drawOval.setLeft(50);  
            drawOval.setTop(300);  
            drawOval.setWidth(100);  
            drawOval.setHeight(100);  
            drawOval.draw();  

            DrawLabel rectLabel = new DrawLabel();  
            rectLabel.setDrawPane(drawPane);  
            rectLabel.setLeft(200);  
            rectLabel.setTop(415);  
            rectLabel.setContents("Rect");  
            rectLabel.draw();  

            DrawRect drawRect = new DrawRect();  
            drawRect.setDrawPane(drawPane);  
            drawRect.setLeft(200);  
            drawRect.setTop(300);  
            drawRect.setWidth(150);  
            drawRect.setHeight(100);  
            drawRect.draw();  

            DrawLabel lineLabel = new DrawLabel();  
            lineLabel.setDrawPane(drawPane);  
            lineLabel.setLeft(400);  
            lineLabel.setTop(415);  
            lineLabel.setContents("Line");  
            lineLabel.draw();  

            DrawLine drawLine = new DrawLine();  
            drawLine.setDrawPane(drawPane);  
            drawLine.setStartPoint(new Point(400,300));  
            drawLine.setEndPoint(new Point(500,400));  
            drawLine.draw();  

            DrawLabel sectorLabel = new DrawLabel();  
            sectorLabel.setDrawPane(drawPane);  
            sectorLabel.setLeft(550);  
            sectorLabel.setTop(415);  
            sectorLabel.setContents("Sector");  
            sectorLabel.draw();  

            DrawSector drawSector = new DrawSector();  
            drawSector.setDrawPane(drawPane);  
            drawSector.setCenterPoint(new Point(550,300));  
            drawSector.setStartAngle(0);  
            drawSector.setEndAngle(90);  
            drawSector.setRadius(100);  
            drawSector.draw();  

        }  
    });  

    ValueChangedHandler shapeRotationSliderValueChangeHandler = new      ValueChangedHandler() {  
        @Override  
        public void onValueChanged(ValueChangedEvent event) {  
            DrawItem[] drawItems = drawPane.getDrawItems();  
            for (int i = 0; i < drawItems.length; i++) {  
                DrawItem drawItem = drawItems[i];  
                if(drawItem instanceof DrawLabel){  
                    continue;  
                }  
                drawItem.rotateTo(event.getValue());  
            }  
            drawPane.redraw();  
        }  
    };  

    Slider shapesRotationSlider = new Slider();  
    shapesRotationSlider.setMinValue(0);  
    shapesRotationSlider.setMaxValue(360);  
    shapesRotationSlider.setNumValues(360);  
    shapesRotationSlider.setWidth(400);  
    shapesRotationSlider.setLeft(25);  
    shapesRotationSlider.setTop(450);  
    shapesRotationSlider.setValue(0);  
    shapesRotationSlider.setTitle("Rotate Shapes");  
    shapesRotationSlider.setVertical(false);  
    shapesRotationSlider.addValueChangedHandler(shapeRotationSliderValueChangeHandler);  
    shapesRotationSlider.draw();  

    VLayout layout = new VLayout();  
    layout.addMember(drawPane);  
    layout.addMember(shapesRotationSlider);  
    layout.draw();  


    layout.draw();  
}  

2 个答案:

答案 0 :(得分:1)

首先,UmbrellaException是“引起的”行所显示的真正异常的包装

所以你真正的例外是:

  

引起:com.google.gwt.core.client.JavaScriptException:   (TypeError):无法调用未定义的方法'create'

如果您在其下方滚动,则会在 Spinner.java 中的 244 行中调用onModuleLoad时看到错误:

  

com.arvindikchari.bspinner.client.Spinner.onModuleLoad(Spinner.java:244)

因此,如果您无法解决问题,请尝试找出错误,然后请发布onModuleLoad方法的完整代码。

UPDATE:

您遇到很多问题:

在绘制布局之前调用onValueChanged的{​​{1}}。要解决此问题,请添加shapeRotationSliderValueChangeHandler并在private boolean firstTime = true中添加:

onValueChanged

PS:对于我无法解决的其他问题,请重新检查整个代码,了解与上述类似的内容。

答案 1 :(得分:1)

首先检查GWT Xml文件是否继承了“entry class”行。

<inherits name="com.smartgwt.Drawing"/>;

还在java文件中添加以下行

import com.smartgwt.*;