{"id":6979,"date":"2014-05-16T01:18:09","date_gmt":"2014-05-16T01:18:09","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/16\/blackberry-java-tableview-calculateverticalscrollamount-exception-collection-of-common-programming-errors\/"},"modified":"2014-05-16T01:18:09","modified_gmt":"2014-05-16T01:18:09","slug":"blackberry-java-tableview-calculateverticalscrollamount-exception-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/16\/blackberry-java-tableview-calculateverticalscrollamount-exception-collection-of-common-programming-errors\/","title":{"rendered":"Blackberry Java TableView: calculateVerticalScrollAmount Exception?-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7d1b4531ab17151cd66ba6ffd52951e9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAntony Scott<\/p>\n<p>I&#8217;m getting a &#8220;TableView(ScrollView).calculateVerticalScrollAmount(XYRect)&#8221; exception when trying to create a table using the following code. I&#8217;ve tried simplifying the fields, but nothing seems to help, any thoughts? The code is similar to that in the Tables Demo supplied with the BB 6 SDK.<\/p>\n<p>It looks like a layout issue, but I can&#8217;t seem to pin down the error.<\/p>\n<pre><code>    \/\/ Create and apply style\n    RegionStyles style = new RegionStyles(BorderFactory.createSimpleBorder(new XYEdges(1, 1, 1, 1), Border.STYLE_SOLID), null, null,\n    null, RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_TOP);\n\n    \/\/ Create the view and controller\n    TableView tableView = new TableView(_tableModel);\n    TableController tableController = new TableController(_tableModel, tableView);\n\n    \/\/ Set the controller focus policy to highlight rows\n    tableController.setFocusPolicy(TableController.ROW_FOCUS);\n\n    \/\/ Set the behaviour of the controller when a table item is clicked\n    tableController.setCommand(new CommandHandler()\n    {\n        \/**\n         * @see CommandHandler#execute(ReadOnlyCommandMetadata, Object)\n         *\/\n        public void execute(ReadOnlyCommandMetadata metadata, Object context)\n        {\n            Dialog.alert(\"Command Executed\");\n        }\n\n    }, null, null);\n\n    tableView.setController(tableController);\n\n    \/\/ Create a DataTemplate that suppresses the third column\n    DataTemplate dataTemplate = new DataTemplate(tableView, 2, 3)\n    {\n        \/**\n         * @see DataTemplate#getDataFields(int)\n         *\/\n        public Field[] getDataFields(int modelRowIndex)\n        {\n            Object[] data = (Object[]) ((TableModel) getView().getModel()).getRow(modelRowIndex);\n\n            Field[] fields = new Field[4];\n            fields[0] = new BitmapField((Bitmap) data[0]);\n            fields[1] = new LabelField(data[1], Field.FOCUSABLE);\n            fields[2] = new LabelField(data[2], Field.FOCUSABLE);\n            fields[3] = new LabelField(data[3], Field.FOCUSABLE);\n\n            return fields;\n        }\n    };\n\n    \/\/ Set up regions\n    dataTemplate.createRegion(new XYRect(0, 0, 1, 2), style);\n    dataTemplate.createRegion(new XYRect(1, 0, 2, 1), style);\n    dataTemplate.createRegion(new XYRect(1, 1, 1, 1), style);\n    dataTemplate.createRegion(new XYRect(2, 1, 1, 1), style);\n\n    \/\/ Specify the size of each column by percentage, and the height of a row        \n    dataTemplate.setColumnProperties(0, new TemplateColumnProperties(15, TemplateColumnProperties.PERCENTAGE_WIDTH));\n    dataTemplate.setColumnProperties(1, new TemplateColumnProperties(15, TemplateColumnProperties.PERCENTAGE_WIDTH));\n    dataTemplate.setColumnProperties(2, new TemplateColumnProperties(70, TemplateColumnProperties.PERCENTAGE_WIDTH));\n    dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));\n    dataTemplate.setRowProperties(1, new TemplateRowProperties(ROW_HEIGHT));\n\n    \/\/ Apply the template to the view\n    tableView.setDataTemplate(dataTemplate);\n    dataTemplate.useFixedHeight(true);\n\n    add(tableView);\n<\/code><\/pre>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2b4dbad007d95dfb69332426d29dd056?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nfirebug<\/p>\n<p>Not sure if you are still struggling with this &#8211; may be benefits for others<\/p>\n<p>in the statement<\/p>\n<pre><code>DataTemplate dataTemplate = new DataTemplate(tableView, 2, 3)\n<\/code><\/pre>\n<p>you have initialized the DataTemplate with 2 rows and 3 columns (assuming you want to suppress 4th column). But inside the function <code>getDataFields<\/code> you are returning 4 fields.<\/p>\n<p>This is causing the crash (the internal code is not monkey proof). Drop the 4th field from array and it should work.<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Antony Scott I&#8217;m getting a &#8220;TableView(ScrollView).calculateVerticalScrollAmount(XYRect)&#8221; exception when trying to create a table using the following code. I&#8217;ve tried simplifying the fields, but nothing seems to help, any thoughts? The code is similar to that in the Tables Demo supplied with the BB 6 SDK. It looks like a layout issue, but I can&#8217;t seem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6979","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6979"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6979\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}