がUncaught exception escaped java.lang.NullPointerException: null
取得GWTアプリでのNullPointerExceptionが、
を取得する方法がわからない
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
は、すべてのオブジェクトだったことがわかりましたエラーを取得しています。ヌルはありませんでした。何が間違っていますか?ここで
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);
}
}
は、スタックトレース
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>
です。ここ
がObserverRegistrationImplクラスである私は、デバッガで問題が続き、それは以下の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;
エラースタックトレースを投稿する – darioo
ダリオが言ったように、スタックトレースを送信します。また、WordListにnullがないことを確認してください。 wlがnullであればwl.getName()を実行しています。例外があります。 –
上記の@darioo、@carlos、wl.getName()はgwtログでokを出力します – jax