Получение NullPointerException в GWT-приложении, но не знаю, как - PullRequest
1 голос
/ 01 декабря 2010

Получение Uncaught exception escaped java.lang.NullPointerException: null

Я получаю ошибку при вызове

private final ObserverRegistrationImpl<Events.WordListEvent> wordListAdditionObservers =  new ObserverRegistrationImpl<Events.WordListEvent>();

public void addWordLists(ArrayList<WordList> wordLists) {
    for(WordList wl : wordLists) {
        GWT.log( "Model: Adding WordList: "+wl.getName());
        this.wordLists.add(wl);
                    //ERROR happens on the line below
        this.wordListAdditionObservers.notifyObservers(this, new Events.WordListEvent(wl)); 
    }
}

Я проверил в режиме отладки и увидел, что wordListAdditionObservers, w1 и this всеобъекты.никто не был нулевым.Что может быть не так?

Вот класс ObserverRegistrationImpl

public class ObserverRegistrationImpl<T> implements Observable<T> {

    private List<Observer<T>> observers = new ArrayList<Observer<T>>();


    @Override
    public void addObserver(Observer<T> o) {
        this.observers.add(o);
    }

    @Override
    public void removeAllObservers() {
        this.observers.clear();
    }

    @Override
    public void removeObserver(Observer<T> o) {
        this.observers.remove(o);
    }

    @Override
    public void notifyObservers(ModelViewInterface model, T event) {
        for(Observer<T> o : this.observers)
            o.notify(model, event);
    }

}

Вот трассировка стека

<code>Uncaught exception escaped
<pre>java.lang.NullPointerException: null
    at com.example.gwt.myapplication.listeditor.client.ObserverRegistrationImpl.notifyObservers(ObserverRegistrationImpl.java:29)
    at com.example.gwt.myapplication.listeditor.client.Model.addWordLists(Model.java:103)
    at com.example.gwt.myapplication.listeditor.client.ControllerAuthentication$2.onXmlParsed(ControllerAuthentication.java:74)
    at com.example.gwt.myapplication.listeditor.client.ControllerAuthentication$2.onXmlParsed(ControllerAuthentication.java:1)
    at com.example.gwt.myapplication.listeditor.client.RemoteRequest.doParseXml(RemoteRequest.java:291)
    at com.example.gwt.myapplication.listeditor.client.RemoteRequest.access$0(RemoteRequest.java:282)
    at com.example.gwt.myapplication.listeditor.client.RemoteRequest$1.onResponseReceived(RemoteRequest.java:209)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:393)
    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.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1714)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
    at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1669)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    at java.lang.Thread.run(Unknown Source)

Я следил за проблемой вотладчик и заметил, что это исключение на следующий код GWT

} catch (InvocationTargetException e) {
  // If we get here, it means an exception is being thrown from
  // Java back into JavaScript
  wrapException(returnValue, e.getTargetException());
  return true;

1 Ответ

0 голосов
/ 31 января 2015

(Ответы в комментариях. Преобразован в вики-ответ сообщества. См. Вопрос без ответов, но проблема решена в комментариях (или расширена в чате) )

ОП написал:

Оказывается, что представление, передаваемое в контроллер, было нулевым, потому что я делал это private ControllerWordLists controller = new ControllerWordLists(this); в переменной экземпляра. Теперь, почему это возможно? Почему не было ошибки компиляции? Это просто странно.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...