Sometimes I need to get a handle to the Application object inside a CustomComponent but getApplication() returns null. Why is this? When will getApplication() return null and is there a way to get to the Application object when it does?
Actually, at the time getApplication() is called, my CustomComponent is in the process of being added to a window - getApplication() is called in the CustomComponent’s constructor. From what you write I can’t call getApplication() there. So, how can I get hold of the application object in the constructor of a CustomComponent?
Well… Calling getApplication() in the constructor is something that just do not work - well, at least it never worked for me
By definition, in the constructor of the CustomComponent, the component is not yet added to the application - and thus cannot access it.
If you really, really need that, maybe sending the application as constructor parameter ?
What I do when I need to init a component using the application is either to use a separate init method that I call after I added the component ; or on some tricky case, override the attach() method on the CustomComponent (calling super.attach() on the first line, and then doing all the specific init).