getApplication() causes NullPointerException

Hey everybody,

i´ve got a Problem and i hope you can help me.

i´ve got a abstract base class that defines my main layout of some custom components. When i extend these class an call getApplication()… the NullPointerException is fired.

I´ve found something about the attach() method but i didn´t understand how to use it. can somebody help me please?

You can’t call getApplication() (or getWindow() or getParent()) in component constructors, because the application reference is not available at construction time - only after the component has been attached to the application.

If you need the application reference in a constructor, either 1) pass the Application reference as a parameter for the constructor, 2) do component construction that requires the reference in attach(), 3) use a ThreadLocal reference to the application object (a thread-local reference to the current UI instance is available in Vaadin 7 with UI.current(), but in Vaadin 6 you need to implement it yourself).

The three solutions for Vaadin 6 are described

hmm ok, but i don´t call the getApplication()-method in the constructor.

it is called after button is pressed.

is it the same problem?

Calling getApplication() in ClickListener (or almost any other listener) should be safe, so I don’t know what your problem could be without more details. As usual, try to narrow the problem down.

hmm i realy dont know why this fault occures :frowning:

actually i´ve solved the problem by passing a reference to the main window.

thanks for your help an merry christmas :smiley: