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: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Manager replace returns IllegalArgumentException: oldField is not a child

[ Edited ]

I have the following code that is ran in a thread that does not have the event lock. I get the event lock by running invokeLater.

 

 

UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
Screen mScreen = UiApplication
        .getUiApplication().getActiveScreen();
if (mScreen instanceof MyScreen) {
	try {
        VerticalFieldManager oldVfm = ((MyScreen) mScreen)
                .getVfm();
        mScreen.replace(oldVfm, newVfm);

        UiApplication.getUiApplication()
                .updateDisplay();

    } catch (IllegalArgumentException e) {
        Logger
                .debug("Illegal argument: "
                        + e.getMessage());
        e.printStackTrace();
    } catch (IllegalStateException e) {
        Logger
                .debug("Illegal state: "
                        + e.getMessage());
        e.printStackTrace();
    }
}
}
});

 

 

I am receiving an IllegalArgumentException: "oldField is not a child" when the invokeLater is ran. The "oldVfm" is added to the active screen with:

 

 

public MyScreen() {
  super();

  this.cfm = new VerticalFieldManager();
  add(this.cfm);
}

 

So how is "oldField" (VerticalFieldManger oldVfm) not a child of the MyScreen class that extends MainScreen?

I don't have to nest the "oldVfm" inside another Manager - that wouldn't make sense...

 

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Manager replace returns IllegalArgumentException: oldField is not a child

Is getVfm() a method you've made?

Developer
Posts: 16,738
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Manager replace returns IllegalArgumentException: oldField is not a child

a problem like this can easily be traced by assigning the field in question to a variable and checking it with the debugger.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: Manager replace returns IllegalArgumentException: oldField is not a child

Yes.

 

 

public MyScreen() {
  super();

  this.cfm = new VerticalFieldManager();
  add(this.cfm);
}

public VerticalFieldManager getVfm(){
  return this.cfm;
}

 

 

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: Manager replace returns IllegalArgumentException: oldField is not a child

[ Edited ]

@simon_hain

 

To clarify, assign my "oldVfm" to a field within my class before I pass it to Manager.replace, correct?

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
Posts: 16,738
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Manager replace returns IllegalArgumentException: oldField is not a child

you already assign it correctly. set a breakpoint at the replace line and check the attributes of the oldVfm, especially the manager which it is assigned to. you can also use getManager to check which manager the field belongs to.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: Manager replace returns IllegalArgumentException: oldField is not a child

Alright, I believe this makes sense.

 

oldVfm.getManager() returns null because oldVfm is the top most Manager (Field) in my class that extends MainScreen.

 

So I can't replace my VerticalFieldManager because it is the only one on the screen. In other words, I cannot replace the old Field on a Screen with a new Field when there is only one Field added to the screen.

 

Screen -> VerticalFieldManager (old)

Screen -> VerticalFieldManager (new)

 

I will try to delete the oldVfm and add the newVfm, but I thought replace() would have done that?

 

 

 

 

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: Manager replace returns IllegalArgumentException: oldField is not a child

Now I've tried nested managers and I still receive an Illegal argument: oldField is not a child.

 

I'm stumped here, I've tried:

 

Screen -> Manager

Screen -> Manager -> Manager

 

Either way, I am unable to replace the Screen's Field (Manager in these cases) with another Field?

 

Replace just performances what delete plus add does.

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
Posts: 298
Registered: ‎05-02-2010
My Device: Bold 9700
My Carrier: Verizon

Re: Manager replace returns IllegalArgumentException: oldField is not a child

[ Edited ]

This is ridiculous.

 

All I am trying to do is replace a screen's only manager with another manager.

 

  1. Screen has a Manager [oldVfm]
  2. Create a new Manager [newVfm]
  3. Loop through a table in a database and output each value to a LabelField
  4. Add each LabelField to a the new Manager [newVfm]
  5. Replace the Screen's Manager [oldVfm] with Manager [newVfm]

That's it...

 

However, if I check the oldVfm Manager it is always null since Manager [oldVfm] is the only manager added to the Screen.

 

 

Manager m = oldVfm.getManager();
if (m != null) {
  mycard.replace(oldVfm, newVfm);
  mycard.invalidate();
} else {
  Logger.debug("oldVfm has no manager.");
}

 

How can I design a solution?

 

Plus what I really don't understand is Screen extends Manager extends Field. So I would think this would be somewhat of a simple solution.

 

--Todd

Windows 7 Enterprise 64-bit (6.1 Build 7600) | Java SE Runtime Environment (build 1.6.0_24-b07) | Eclipse Version: 3.6.2 [M20110210-1200] | BlackBerry Eclipse Plug-in: 1.3.0.201102031007-19 | Java Compiler level: 1.3 | Targeting devices running OS 5 | Simulators: JDE 5.0 packaged 9700, 9630, 9300
Developer
Posts: 16,738
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Manager replace returns IllegalArgumentException: oldField is not a child

The main manager of a mainscreen cannot be replaced i think. you can add a manager for the whole screen and replace this one.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter