Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12450] Android: TableViewRow with className crash when adding a view and scrolling

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2017-07-26T04:21:13.000+0000
Affected Version/sRelease 3.1.0
Fix Version/sn/a
ComponentsAndroid
Labelsexalture
ReporterMartin Guillon
AssigneeEric Merriman
Created2012-12-23T15:46:40.000+0000
Updated2017-07-26T04:21:13.000+0000

Description

Problem description

Adding a view to a row on the fly, if the row has className enabled, results in a crash as soon as the table scrolls.

Comments

Lets say you want to implement a menu on row. The "lighter" way is to add the menu when necessary and remove it as soon as possible. If you are using the 'className' property of the row then a crash occurs while scrolling (reuse of a cell). If you remove the className property in the code below, then it works. In more complex code of mine I can see that the reuse works perfectly without className. So using className should work as well (even better).

Steps to reproduce

Use the following code; click on a row, then scroll down to see the crash.
var win = Titanium.UI.createWindow();
win.backgroundColor = '#ccc';

var tableview = Ti.UI.createTableView();
win.add(tableview);

var rowData = [];
for (var i = 0; i < 100; i++) {
	var row = Ti.UI.createTableViewRow({
		title : 'row ' + i,
		height : 90,
		className : 'myrow'
	});
	row.view = Ti.UI.createView({
		left : 0,
		right : 0,
		top : 0,
		bottom : 0,
		backgroundColor : 'blue'
	})
	row.add(row.view);
	rowData.push(row);
};
tableview.data = rowData;

tableview.addEventListener('click', function(e) {
	if (e.row) {
		Ti.API.info('testing ')
		if (!e.row.menu || e.row.menu === null) {
			e.row.menu = Ti.UI.createView({
				width : 50,
				right : 0,
				backgroundColor : 'black'
			})
			e.row.view.add(e.row.menu);
		} else {
			e.row.view.remove(e.row.menu);
			e.row.menu = null;
		}
	}
})

win.open();
The error reported: E/TiApplication( 4545): java.lang.ArrayIndexOutOfBoundsException: length=0; index=0 E/TiApplication( 4545): at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.applyChildProperties(TiTableViewRowProxyItem.java:176)

Comments

  1. jithinpv 2013-03-15

    Issue reproduces with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 (03/11/13 15:43 0c88429) Titanium SDK version: 3.0.2 (02/07/13 16:46 a4def81) Device: Samsung galaxy s duos Android version: 4.0.4 jithinpv
  2. Biju pm 2013-06-25

    The issue cannot reproduce with the release master 3.2.0 Tested with: Titanium SDK version: 3.2.0 Tested on Device: Samsung galaxy s duos Android version: 4.0.4
  3. Sunila 2014-09-23

    I couldn't reproduce the issue with latest master. Device Nexus 4.3
  4. Lee Morris 2017-07-26

    I am unable to reproduce this issue with the following environment; Pixel (7.1) Studio 4.9.0.201705302345 Ti SDK 6.1.1 GA Appc NPM 4.2.9 Appc CLI 6.2.2 Ti CLI 5.0.14 Alloy 1.9.11 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131

JSON Source