不同类的GWT类方法不调用&得到UmbrellaException [英] GWT class method of different class not calling & getting UmbrellaException

查看:166
本文介绍了不同类的GWT类方法不调用&得到UmbrellaException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以我通过了UserID& 密码进行验证,然后它将导航到下一页。



我的代码:

  public class Test2 extends Composite {

HelloUIBinder hb;

AnimationHelper animationHelper;
TestPage tp;

字符串strEmail,strPass;

private static Test2UiBinder uiBinder = GWT.create(Test2UiBinder.class);

接口Test2UiBinder扩展了UiBinder< Widget,Test2> {
}

@UiField TextBox txtEmail;
@UiField PasswordTextBox txtPass;
@UiField按钮btnLogin;

public Test2(){
initWidget(uiBinder.createAndBindUi(this));

btnLogin.addClickHandler(新函数clickhandler(){

@覆盖
公共无效的onClick(ClickEvent事件){
// TODO自动生成方法存根

strEmail = txtEmail.getText()的toString();
strPass = txtPass.getText()的toString();

Window.alert(strEmail );
Window.alert(strPass);

GWT.setUncaughtExceptionHandler(新GWT.UncaughtExceptionHandler(){

@覆盖
公共无效onUncaughtException( Throwable的五){
// TODO自动生成方法存根
Throwable的UN =的unwrap(E);

Window.alert(un.toString());
}
});

hb.onLogin(strEmail,strPass);
}
});
}

公共Throwable的解包(Throwable的E)
{
如果(E的instanceof UmbrellaException)
{
UmbrellaException UE =(UmbrellaException) Ë;
if(ue.getCauses()。size()== 1)
{
return unwrap(ue.getCauses()。iterator()。next());
}
}
return e;






$ b

通过这段代码,我想调用onLogin()



代码为onLogin:

  public void onLogin(String email,String pass)
{
Window.alert(email);
Window.alert(pass);

if(email ==abc@yahoo.com&& pass ==abc123)
{
RootPanel.get()。clear();

tp = new TestPage();
RootPanel.get()。add(tp);

animationHelper.goTo(tp,Animation.SLIDE);
}
else
{
Window.alert(Authentication Failed);


$ / code>

但是,在运行应用程序时,我收到错误消息:

 com.google.gwt.core.client.JavaScriptException:(TypeError):'null'不是一个对象 

那么这个错误有什么问题?

请尽快告诉我任何解决方案。



预先致谢。

解决方案

基本上我们有一个NullPointerException。 onLogin中唯一可以为null的东西似乎是animationHelper,并且您没有发布任何代码来初始化它。然而,有一个堆栈跟踪会更可靠。你应该改变你的代码来提供跟踪。如果您需要更多信息,您应该


  • 发布堆栈跟踪

  • 发布用于初始化animationHelper的代码


I want to call method from different class for navigation of pages.

So I'm passing "UserID" & "Password" for authentication and after that it will navigate to next page.

My Code:

public class Test2 extends Composite {

HelloUIBinder hb;

AnimationHelper animationHelper;
TestPage tp;

String strEmail, strPass;

private static Test2UiBinder uiBinder = GWT.create(Test2UiBinder.class);

interface Test2UiBinder extends UiBinder<Widget, Test2> {
}

@UiField TextBox txtEmail;
@UiField PasswordTextBox txtPass;
@UiField Button btnLogin;

public Test2() {
    initWidget(uiBinder.createAndBindUi(this));

    btnLogin.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub

            strEmail = txtEmail.getText().toString();
            strPass = txtPass.getText().toString();

            Window.alert(strEmail);
            Window.alert(strPass);

            GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {

                @Override
                public void onUncaughtException(Throwable e) {
                    // TODO Auto-generated method stub
                    Throwable un = unwrap(e);

                    Window.alert(un.toString());
                }
            });

            hb.onLogin(strEmail, strPass);
        }
    });
}

public Throwable unwrap(Throwable e)
{
    if(e instanceof UmbrellaException)
    {
        UmbrellaException ue = (UmbrellaException) e;
        if(ue.getCauses().size() == 1)
        {
            return unwrap(ue.getCauses().iterator().next());
        }
    }
    return e;
}
}

By this code, I want to call onLogin() method of HelloUIBinder class by passing two parameters.

Code for onLogin :

public void onLogin(String email, String pass)
{
    Window.alert(email);
    Window.alert(pass);

    if(email == "abc@yahoo.com" && pass == "abc123")
    {
        RootPanel.get().clear();

        tp = new TestPage();
        RootPanel.get().add(tp);

        animationHelper.goTo(tp, Animation.SLIDE);
    }
    else
    {
        Window.alert("Authentication Failed");
    }
}

But, while running application I'm getting Error Message:

"com.google.gwt.core.client.JavaScriptException: (TypeError): 'null' is not an object"

So what's an issue regarding this error ?

Please tell me any solution as soon as possible.

Thanks in advance.

解决方案

Essentially we have a NullPointerException. The only thing that can be null in onLogin seems to be animationHelper so far and, you didn't post any code to initialize it. However, things would be more relyable having a stacktrace. You should really change your code to deliver the trace. If you need more information you should

  • Post the stacktrace
  • Post the code used to initialize animationHelper

这篇关于不同类的GWT类方法不调用&amp;得到UmbrellaException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆