tags:

views:

370

answers:

1

class Scr extends MainScreen {

public Scr() {

    TableLayoutManager outerTable = new TableLayoutManager(new int[]
                                                                  {
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.SPLIT_REMAINING_WIDTH
                        },0);
    TableLayoutManager innerTable = new TableLayoutManager(new int[]
                                                                   {
                                                                   TableLayoutManager. USE_PREFERRED_SIZE,
                                                                   TableLayoutManager.USE_PREFERRED_SIZE

                                                                   }, Manager.USE_ALL_WIDTH);

    innerTable.add(new LabelField("titleField"));
    innerTable.add(new LabelField("title"));
    innerTable.add(new LabelField("descriptionfield"));
    innerTable.add(new LabelField("description"));
    innerTable.add(new LabelField("rating field"));
    innerTable.add(new LabelField("***"));
    outerTable.add(new BitmapField(Bitmap.getBitmapResource("mac.png"),Field.FOCUSABLE));
 outerTable.add(innerTable);
 add(outerTable);

 outerTable.add(new BitmapField(Bitmap.getBitmapResource("fire.png"),Field.FOCUSABLE));
 outerTable.add(innerTable);
 add(outerTable);

}

When I add another Bitmap and innerTable to the outerTable, and outerTable to the screen. The application gives a runtime jvm error 104 "Field added to a manager when it is already parented".

The problem arises when I add another innerTable to outerTable. Not when I add Bitmap to outerTable.

+1  A: 

innerTable has already been added to outerTable, you can't add it a second time. this is because one instance of a control defines some member which tells where the control and how it displays, like the parent and size. those members obviously cannot have mumtiple values. so you have to create another control, which duplicate the first one, so that it can have its own parent and size.

here, you have to create another instance of TableLayoutManager (maybe name it innerTable2) and add it to outerTable. also, outerTable is added 2 times, which will trigger the same error, you have to create another instance of outerTable.

you should write: (note that there are better ways to do it...)

public Scr() {
    TableLayoutManager outerTable = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.SPLIT_REMAINING_WIDTH
                        },0);
    TableLayoutManager outerTable2 = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.SPLIT_REMAINING_WIDTH
                        },0);
    TableLayoutManager innerTable = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.USE_PREFERRED_SIZE
                        },Manager.USE_ALL_WIDTH);
    TableLayoutManager innerTable2 = new TableLayoutManager(new int[]{
                         TableLayoutManager.USE_PREFERRED_SIZE,
                         TableLayoutManager.USE_PREFERRED_SIZE
                        },Manager.USE_ALL_WIDTH);

    innerTable.add(new LabelField("titleField"));
    innerTable.add(new LabelField("title"));
    innerTable.add(new LabelField("descriptionfield"));
    innerTable.add(new LabelField("description"));
    innerTable.add(new LabelField("rating field"));
    innerTable.add(new LabelField("***"));
    outerTable.add(new BitmapField(Bitmap.getBitmapResource("mac.png"),Field.FOCUSABLE));
    outerTable.add(innerTable);
    add(outerTable);

    innerTable2.add(new LabelField("titleField"));
    innerTable2.add(new LabelField("title"));
    innerTable2.add(new LabelField("descriptionfield"));
    innerTable2.add(new LabelField("description"));
    innerTable2.add(new LabelField("rating field"));
    innerTable2.add(new LabelField("***"));
    outerTable2.add(new BitmapField(Bitmap.getBitmapResource("fire.png"),Field.FOCUSABLE));
    outerTable2.add(innerTable2);
    add(outerTable2);
}

note that you have a lot of duplicate code here. you can factor the innerTable creation into a function which creates a TableLayoutManager, add all required labels and return the new configured TableLayoutManager.

Adrien Plisson
Thanksssssss. U made things so easy
Bohemian
i edited my post to add some explanations. it is worth reading it again.
Adrien Plisson
yeah thats better
Bohemian