Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 71
Registered: ‎03-10-2009
My Device: Not Specified
Accepted Solution

Manager is null in PopupScreen

[ Edited ]

Ignore this thread, I just made a stupid mistake in my own code and it had nothing to do with PopupScreen.

 

  Hi All,

 

I have the following problem and I can't really believe my eyes... I descending from PopupScreen, I pass a new Manager instance to the inherited constructor by calling super and then on the following line getManager() returns null. (And of course the add calls fail.) E.g.:

 

public class Dialog extends PopupScreen implements FieldChangeListener {

[....]

 

public Dialog( Properties conf, String text[], String yes, String no, Listener listener ) {
        super( new VerticalFieldManager() );

 

        log.log( "manager = " + getManager() ); // says manager is null
        this.listener = listener;
        
        for ( int i = 0; i < text.length; i++ ) {
            add( new LabelField( text[i], Field.FIELD_HCENTER ) ); // Throws NPE, while text and text[i] is NOT null. For sure.
        }

 

 

Anyone seen something like this before? I checked some of my earlier projects and (no surprise) I was able to do the same thing without ay trickery. (Actually there's not much one could do here, since the call to the inherited constructor has to be the first instruction...) Now this fails for me on 4.2.1, 4.5.0 and 4.7.0.

 

At first I thought that it's some undocumented threading issue (I was assembling the UI in a non GUI thread before calling enterEventDispatcher), but that works in all of my projects and I changed the startup sequence in the end so that know it happens after calling enterEventDispatcher. I even tried moving it to the event thread but it still fails consequently. (Also I looking at the code there shouldn't be any threading issues there. At least as long as it's a java virtrual machine and not just something similar.)

 

  Laszlo

Developer
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: Manager is null in PopupScreen

Hi atleta,

    "log.log( "manager = " + getManager() ); // says manager is null" - sorry to say, you are not clear about getManager(). this method will return the parent manager object to which that field has been added and not the manager added to that field. Since you are calling this method from popupscreen it will return because popupscreen was not added to any manager.

 

    "add( new LabelField( text[i], Field.FIELD_HCENTER ) ); // Throws NPE, while text and text[i] is NOT null. For sure." -

          Its clear that LabelField object what you created is null, even text[i] can be null becuase text[i] is null, then LabelField will be created with empty text. We have to identify the reason why LabelField object creation is failing. can you please post the completed exception what you got and sample code instead of snippet. so it will be easy to identify.

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Developer
Posts: 71
Registered: ‎03-10-2009
My Device: Not Specified

Re: Manager is null in PopupScreen

  Hi Vignesh,

 

Thanks for looking into my problem. Well, getManager may mean what you say as it's defined in Field (and not in Screen). It totally makes sense. Anyway, to me the manager still seems to be null as it's the only thing that can be. Some additional info: apparently it has nothing to do with PopupScreen as I tried rolling back the code to use a different super class and the problem is the same.

 

 


zany wrote:

    "add( new LabelField( text[i], Field.FIELD_HCENTER ) ); // Throws NPE, while text and text[i] is NOT null. For sure." -

          Its clear that LabelField object what you created is null, even text[i] can be null becuase text[i] is null, then LabelField will be created with empty text. We have to identify the reason why LabelField object creation is failing. can you please post the completed exception what you got and sample code instead of snippet. so it will be easy to identify.


LabelField just cannot be null. The new operator can never ever yield null in java. It may throw an exception (a RuntimeException) or an Error, but can never return null. Neither text or text[i] is null in this case. Though they could be, but text[i] is logged and it happens to be OK. Also if it was null then the exception would be reported to be thrown from inside LabelField.<init> and not Dialog.add .

 

Highlighted
Developer
Posts: 71
Registered: ‎03-10-2009
My Device: Not Specified

Re: Manager is null in PopupScreen

... and this is how getting away from the problem, sleeping and talking about it (posting to the forum) helps to solve it... I have accidentally overridden the add method to be able to add components from the outside to a specific part of the window (just as with the standard Dialog class). That was throwing the exception when called from the constructor as the manager used in there would be initialize later. Sorry, my bad, thanks for your efforts Smiley Happy.