01-19-2011 10:19 PM - last edited on 01-19-2011 10:22 PM
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...
01-20-2011 09:34 AM
Is getVfm() a method you've made?
01-20-2011 09:45 AM
a problem like this can easily be traced by assigning the field in question to a variable and checking it with the debugger.
01-20-2011 09:46 AM
Yes.
public MyScreen() {
super();
this.cfm = new VerticalFieldManager();
add(this.cfm);
}
public VerticalFieldManager getVfm(){
return this.cfm;
}
01-20-2011 09:48 AM - last edited on 01-20-2011 09:49 AM
@simon_hain
To clarify, assign my "oldVfm" to a field within my class before I pass it to Manager.replace, correct?
01-20-2011 09:51 AM
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.
01-20-2011 11:25 AM
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?
01-20-2011 03:20 PM
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.
01-20-2011 09:49 PM - last edited on 01-20-2011 09:52 PM
This is ridiculous.
All I am trying to do is replace a screen's only manager with another manager.
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.
01-21-2011 03:05 AM
The main manager of a mainscreen cannot be replaced i think. you can add a manager for the whole screen and replace this one.