Getting Uncaught exception escaped java.lang.NullPointerException: null
i am getting the error when calling
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));
}
}
I checked in Debug mode and saw that wordListAdditionObservers
, w1
and this
were all objects. none were null. What could be wrong开发者_开发知识库?
Here is the ObserverRegistrationImpl class
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);
}
}
Here is the stacktrace
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)</pre>
I followed the problem in the debugger and noticed that it is thowing an exception at the following GWT code
} 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;
(Answered in comments. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
It turns out the view getting passed to the controller was null because I was doing this
private ControllerWordLists controller = new ControllerWordLists(this);
in an instance variable. Now why is that possible? Why was there no compile error? That is just weird.
I 've had the same stack trace. It should be double checked if there isn't any array of objects . GWT has problems with it. Better change it to List or List of Lists ...
精彩评论