Blackberry Java TableView:calculateVerticalScrollAmount异常?
在尝试使用以下代码创建表时,出现“TableView(ScrollView).calculateVerticalScrollAmount(XYRect)”异常。我试着简化这些领域,但似乎没有任何帮助,有什么想法吗?该代码与BB 6 SDK附带的Tables演示中的代码类似 这看起来像是布局问题,但我似乎无法确定错误Blackberry Java TableView:calculateVerticalScrollAmount异常?,java,blackberry,user-interface,Java,Blackberry,User Interface,在尝试使用以下代码创建表时,出现“TableView(ScrollView).calculateVerticalScrollAmount(XYRect)”异常。我试着简化这些领域,但似乎没有任何帮助,有什么想法吗?该代码与BB 6 SDK附带的Tables演示中的代码类似 这看起来像是布局问题,但我似乎无法确定错误 // Create and apply style RegionStyles style = new RegionStyles(BorderFactory.creat
// 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);
不确定你是否仍在努力解决这个问题——这可能对其他人有好处 在声明中
DataTemplate dataTemplate = new DataTemplate(tableView, 2, 3)
您已经用2行3列初始化了DataTemplate(假设您想要抑制第4列)。但是在函数getDataFields
中,您将返回4个字段
这是导致崩溃的原因(内部代码不是防猴子的)。
从数组中删除第四个字段,它应该可以工作