Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript GWT无法读取属性';示例';未定义的_Javascript_Java_Gwt_Gwt Super Dev Mode - Fatal编程技术网

Javascript GWT无法读取属性';示例';未定义的

Javascript GWT无法读取属性';示例';未定义的,javascript,java,gwt,gwt-super-dev-mode,Javascript,Java,Gwt,Gwt Super Dev Mode,我正在学习GWT,目前正在努力学习RPC。我有一个简单的项目:一个标签,一个文本框,一个outputLabel和一个按钮。 我想当用户在文本框中输入他的名字并按下“发送”按钮时,他会从服务器收到一条消息“你好”+名字+“这里说的是服务器”-愚蠢的例子。 然而,在我的客户机中,我有一个包GUI、一个包服务和我的entrypoint类 public class TestGwt270 implements EntryPoint { public void onModuleLoad() {

我正在学习GWT,目前正在努力学习RPC。我有一个简单的项目:一个标签,一个文本框,一个outputLabel和一个按钮。 我想当用户在文本框中输入他的名字并按下“发送”按钮时,他会从服务器收到一条消息“你好”+名字+“这里说的是服务器”-愚蠢的例子。 然而,在我的客户机中,我有一个包GUI、一个包服务和我的entrypoint类

public class TestGwt270 implements EntryPoint {

public void onModuleLoad() 
{       
    TestGwt270ClientImpl clientImpls = new TestGwt270ClientImpl("/TestGwt270/testgwt270service");
    GWT.log("Main "+GWT.getModuleBaseURL() );
    RootPanel.get().add(clientImpls.getMainGUI());
}
MyGui:

public class MainGUI extends Composite 
{   
    private TestGwt270ClientImpl serviceImpl;

    private VerticalPanel vPanel;

    private TextBox inputTB;
    private Label outputLbl;

    public MainGUI(TestGwt270ClientImpl serviceImpl)
    {
        this.vPanel = new VerticalPanel();
        initWidget(vPanel);

        this.inputTB = new TextBox();
        this.inputTB.setText("Gib deinen Namen ein");
        this.outputLbl = new Label("Hier kommt der output");
        this.vPanel.add(this.inputTB);
        this.vPanel.add(this.outputLbl);

        Button sendBtn = new Button("send");
        sendBtn.addClickHandler(new MyClickhandler()); 
        this.vPanel.add(sendBtn);       
    }

    public void updateOutputLbl(String output)
    {
        this.outputLbl.setText(output);
    }

    private class MyClickhandler implements ClickHandler
    {
        @Override
        public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub
            serviceImpl.sayHello(inputTB.getText());
        }       
    }   
}
服务:

@RemoteServiceRelativePath("testgwt270service")
public interface TestGwt270Service extends RemoteService 
{
    String sayHello(String name);
}
异步服务:

public interface TestGwt270ServiceAsync 
{
    void sayHello(String name, AsyncCallback<String> callback);
}
客户端实现:

public class TestGwt270ClientImpl implements TestGwt270ServiceClientInt
{
    private TestGwt270ServiceAsync service;
    private MainGUI maingui;

    public TestGwt270ClientImpl(String url) 
    {
        GWT.log(url);
        // TODO Auto-generated constructor stub
        this.service = GWT.create(TestGwt270Service.class);
        ServiceDefTarget endpoint = (ServiceDefTarget) this.service;
        endpoint.setServiceEntryPoint(url);

        this.maingui = new MainGUI(this);
    }

    public MainGUI getMainGUI()
    {
        return this.maingui;
    }

    @Override
    public void sayHello(String name) {
        // TODO Auto-generated method stub
        this.service.sayHello(name, new MyCallback());
    }

    private class MyCallback implements AsyncCallback<String>
    {
        @Override
        public void onFailure(Throwable arg0) {
            // TODO Auto-generated method stub
            GWT.log("Failure");
            maingui.updateOutputLbl("An Error has occured");
        }

        @Override
        public void onSuccess(String arg0) {
            // TODO Auto-generated method stub
            GWT.log("Success");
            maingui.updateOutputLbl(arg0);
        }       
    }
}
我的问题是,当我按下按钮将我的名字发送到服务器时,出现以下错误:

handlermager.java:129 Uncaught com.google.gwt.event.shared.umbralleException:捕获异常:(TypeError):无法读取未定义的属性“sayHello_2_g$”


我不知道这个错误是从哪里来的,我希望你能帮助我。

我自己找到了答案-我犯了一个简单的错误:

在MyGUI类中,我得到了以下信息:

public class MainGUI extends Composite 
{ 
    private TestGwt270ClientImpl serviceImpl;
    ...
    public MainGUI(TestGwt270ClientImpl serviceImpl)
    {
        ...
我忘了分配serviceImpl 修复方法:


我自己找到了答案——我犯了一个简单的错误:

在MyGUI类中,我得到了以下信息:

public class MainGUI extends Composite 
{ 
    private TestGwt270ClientImpl serviceImpl;
    ...
    public MainGUI(TestGwt270ClientImpl serviceImpl)
    {
        ...
我忘了分配serviceImpl 修复方法:

好的,谢谢你的编辑:)下次我做对了好的,谢谢你的编辑:)下次我做对了
public class MainGUI extends Composite 
{ 
    private TestGwt270ClientImpl serviceImpl;
    ...
    public MainGUI(TestGwt270ClientImpl serviceImpl)
    {
        ...
public class MainGUI extends Composite 
{   
    private TestGwt270ClientImpl serviceImpl;
    ...
    public MainGUI(TestGwt270ClientImpl serviceImpl)
    {
        this.serviceImpl = serviceImpl; //this line is the solution to my problem
        ...