2012-08-29 36 views
1

我想調用不同類的方法來瀏覽頁面。不同類的GWT類方法不調用和獲取UmbrellaException

所以我通過「UserID」&「密碼」進行身份驗證,然後它將導航到下一頁。

我的代碼:

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; 
} 
} 

通過這個代碼,我想傳遞兩個參數來調用onLogin()HelloUIBinder類的方法。

代碼onLogin:

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

    if(email == "[email protected]" && pass == "abc123") 
    { 
     RootPanel.get().clear(); 

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

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

但是,在運行應用程序我收到錯誤消息:

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

那麼,什麼是一個問題,關於這個錯誤?

請儘快告訴我任何解決方案。

在此先感謝。

回答

1

本質上,我們有一個NullPointerException。 onLogin中唯一可以爲null的東西似乎是animationHelper,並且您沒有發佈任何代碼來初始化它。然而,有一個堆棧跟蹤會更可靠。你應該改變你的代碼來提供跟蹤。如果您需要更多,你應該

  • 後堆棧跟蹤
  • 後用來初始化animationHelper
代碼信息
相關問題