2011-08-24 57 views
2

尝试使用下面的代码来创建表时,我得到一个“的TableView(滚动型).calculateVerticalScrollAmount(XYRect)”异常。我尝试过简化田地,但似乎没有任何帮助,有什么想法?代码与BB 6 SDK提供的Tables Demo类似。黑莓的Java的TableView:calculateVerticalScrollAmount异常?

它看起来像一个布局的问题,但我似乎无法拖住错误。

// Create and apply style 
    RegionStyles style = new RegionStyles(BorderFactory.createSimpleBorder(new XYEdges(1, 1, 1, 1), Border.STYLE_SOLID), null, null, 
    null, RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_TOP); 

    // Create the view and controller 
    TableView tableView = new TableView(_tableModel); 
    TableController tableController = new TableController(_tableModel, tableView); 

    // Set the controller focus policy to highlight rows 
    tableController.setFocusPolicy(TableController.ROW_FOCUS); 

    // Set the behaviour of the controller when a table item is clicked 
    tableController.setCommand(new CommandHandler() 
    { 
     /** 
     * @see CommandHandler#execute(ReadOnlyCommandMetadata, Object) 
     */ 
     public void execute(ReadOnlyCommandMetadata metadata, Object context) 
     { 
      Dialog.alert("Command Executed"); 
     } 

    }, null, null); 

    tableView.setController(tableController); 

    // Create a DataTemplate that suppresses the third column 
    DataTemplate dataTemplate = new DataTemplate(tableView, 2, 3) 
    { 
     /** 
     * @see DataTemplate#getDataFields(int) 
     */ 
     public Field[] getDataFields(int modelRowIndex) 
     { 
      Object[] data = (Object[]) ((TableModel) getView().getModel()).getRow(modelRowIndex); 

      Field[] fields = new Field[4]; 
      fields[0] = new BitmapField((Bitmap) data[0]); 
      fields[1] = new LabelField(data[1], Field.FOCUSABLE); 
      fields[2] = new LabelField(data[2], Field.FOCUSABLE); 
      fields[3] = new LabelField(data[3], Field.FOCUSABLE); 

      return fields; 
     } 
    }; 

    // Set up regions 
    dataTemplate.createRegion(new XYRect(0, 0, 1, 2), style); 
    dataTemplate.createRegion(new XYRect(1, 0, 2, 1), style); 
    dataTemplate.createRegion(new XYRect(1, 1, 1, 1), style); 
    dataTemplate.createRegion(new XYRect(2, 1, 1, 1), style); 

    // Specify the size of each column by percentage, and the height of a row   
    dataTemplate.setColumnProperties(0, new TemplateColumnProperties(15, TemplateColumnProperties.PERCENTAGE_WIDTH)); 
    dataTemplate.setColumnProperties(1, new TemplateColumnProperties(15, TemplateColumnProperties.PERCENTAGE_WIDTH)); 
    dataTemplate.setColumnProperties(2, new TemplateColumnProperties(70, TemplateColumnProperties.PERCENTAGE_WIDTH)); 
    dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT)); 
    dataTemplate.setRowProperties(1, new TemplateRowProperties(ROW_HEIGHT)); 

    // Apply the template to the view 
    tableView.setDataTemplate(dataTemplate); 
    dataTemplate.useFixedHeight(true); 

    add(tableView); 

回答

4

不知道,如果你还在为此苦苦挣扎 - 可能是为他人

在声明

DataTemplate dataTemplate = new DataTemplate(tableView, 2, 3) 

你有2行3列初始化的DataTemplate

收益(假设你想压制第4栏)。但功能getDataFields内要返回4个领域。

这是导致飞机失事的原因(内部代码是不是猴子的证明)。 下降,由阵列第四场,它应该工作。