getMainWindow() throws NullPointerException

Hi everybody,

everytime i try to use the getMainWindow() - Method, a NPE is thrown :frowning:

Here is my code:


...
MyApplication.getInstance().getMainWindow().showNotification(myNotification);
...

an the init method:


public class MyApplication extends Application{
private static ThreadLocal<MyApplication> threadLocal = new ThreadLocal<MyApplication>();

public void init(){
        setInstance(this);
        Window w = new Window();
        setMainWindow(w);
....


public static MyApplication getInstance() {
     return threadLocal.get();
}

public static void setInstance(MyApplication application) {
     threadLocal.set(application);
}

Did you also implement the TransactionListener as described
here
?

your my man… i´ve used another code snippet without these transactionlistner part. now it works so far.

the part:

 Lang.setLocal(getLocal()) 

must bei changed to

 setLocal(getLocal()) 

is that ok?

I think you actually don’t need the locale part at all because i think in the example they use another threadlocal called Lang.which you don’t have. It also seems like the top example is outdated and it is recommended to use the bottom one with HttpServletRequestListener.

ok thanks for your help :smiley: