2010-12-01 5 views
1

Erste Uncaught exception escaped java.lang.NullPointerException: nullErste Nullpointer in GWT app aber nicht sicher, wie

ich die Störung erhalte, wenn

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

Aufruf ich im Debug-Modus aktiviert und sah, dass wordListAdditionObservers, w1 und this alle Objekte waren. keiner war null. Was könnte falsch sein? Hier

ist die ObserverRegistrationImpl Klasse

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

} 

Hier wird die 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> 

ich das Problem im Debugger verfolgt und festgestellt, dass es eine Ausnahme bei dem folgenden GWT-Code wird thowing

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

Veröffentlichen Sie die Fehler-Stack-Trace – darioo

+0

Wie Darioo sagte, post die Stack-Trace. Überprüfen Sie aber auch, dass in der WordList kein Nullwert vorhanden ist. Sie tun wl.getName(), wenn wl Null ist, haben Sie Ihre Ausnahme. –

+0

@darioo oben hinzugefügt, @carlos, die wl.getName() druckt ok im gwt log – jax

Antwort

0

(Beantwortet in Kommentaren. Konvertiert in eine Community-Wiki-Antwort. Siehe Question with no answers, but issue solved in the comments (or extended in chat))

Die OP schrieb:

Es stellt sich heraus den Blick auf den Controller übergeben bekommen null war, weil ich diese private ControllerWordLists controller = new ControllerWordLists(this); in einer Instanzvariablen tat. Warum ist das möglich? Warum gab es keinen Kompilierungsfehler? Das ist einfach komisch.

Verwandte Themen