Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26155] Android: ListView setItems causes error after updateItemAt used with custom template

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-07-03T16:38:30.000+0000
Affected Version/sRelease 7.2.0
Fix Version/sRelease 7.5.0
ComponentsAndroid
Labelsdefect
ReporterRussell Kenny
AssigneeGary Mathews
Created2018-06-22T20:24:20.000+0000
Updated2018-09-20T14:11:29.000+0000

Description

I am attempting to use ListView to hold a series of Switch + Labels for a question and answer app. When the user selects one answer (either by clicking the switch or clicking the label), I am setting all other Switches to false so that only one answer can be selected. Below is the minimum code to reproduce the issue. What you will see is if the user does not click any Switches / Labels and just clicks the button, the first set of answers is replaced by the second set of answers without any issue. If the user clicks a Switch / Label, which causes updateItemAt() to be used on each row, then when the button is pressed to replace the answers shown, an error occurs. ----
<Alloy>
<Window id="questWin" title="Questions and Answers">
	<View layout="horizontal">
	  <ListView top="0" left="24dp" width="Ti.UI.FILL" height="Ti.UI.SIZE" id="answerList" defaultItemTemplate="answerTmpl" separatorColor="#BBB" onItemclick="clickAns">
	    <Templates>
	      <ItemTemplate top="8dp" bottom="8dp" width="Ti.UI.FILL" height="Ti.UI.SIZE" name="answerTmpl">
	        <View top="0" left="0" layout="horizontal" width="Ti.UI.FILL" height="Ti.UI.SIZE">
	          <Switch left="0" width="Ti.UI.SIZE" height="Ti.UI.SIZE" style="Titanium.UI.Android.SWITCH_STYLE_CHECKBOX" bindId="ansCheck" />
	          <Label left="8dp" width="Ti.UI.FILL" height="Ti.UI.SIZE" bindId="ansLabel" />
	        </View>
	      </ItemTemplate>
	    </Templates>
	    <ListSection id="answerSec" />
	  </ListView>
	  <Button top="12dp" width="160dp" onClick="clickSubmitBtn">Submit</Button>
	</View>  
</Window>
</Alloy>
----
// Arguments passed into this controller can be accessed via the $.args object directly or:
var args = $.args;
var giSelAns = null;

function clickAns(e) {
	giSelAns = e.itemIndex;

	for (var iCnt = 0; iCnt < $.answerSec.items.length; iCnt++) {
		var item = $.answerSec.getItemAt(iCnt);
		if (iCnt == giSelAns)
			item.ansCheck.value = true;
		else
			item.ansCheck.value = false;
		$.answerSec.updateItemAt(iCnt, item);
	}
}

function clickSubmitBtn() {
	// Skipping code to check correct, answer, etc.
	answers = [
		{ ansLabel: { text: "Second Answer 1" }, ansCheck: { isCorrect: false } },
		{ ansLabel: { text: "Second Answer 2" }, ansCheck: { isCorrect: true } },
		{ ansLabel: { text: "Second Answer 3" }, ansCheck: { isCorrect: false } },
	];
	$.answerSec.setItems(answers);	
}

$.questWin.addEventListener("open", function() {
	answers = [
		{ ansLabel: { text: "First Answer 1" }, ansCheck: { isCorrect: true } },
		{ ansLabel: { text: "First Answer 2" }, ansCheck: { isCorrect: false } },
		{ ansLabel: { text: "First Answer 3" }, ansCheck: { isCorrect: false } },
	];
	$.answerSec.setItems(answers);
});

$.questWin.addEventListener("close", function(){
  $.destroy();
});

$.questWin.open();
---- {noformat} [INFO] : ViewRootImpl: finishMotionEvent: handled = true stage=10: View Post IME stage,inputElapseTime=1 eventTime = 23749878 downTime = 23749878 title= edu.bju.logia/org.appcelerator.titanium.TiActivity [ERROR] : TiApplication: (main) [11565,11565] Sending event: exception on thread: main msg:java.lang.IllegalArgumentException: Unable to convert null to boolean.; Titanium 7.2.0,2018/06/07 05:21,undefined [ERROR] : TiApplication: java.lang.IllegalArgumentException: Unable to convert null to boolean. [ERROR] : TiApplication: at org.appcelerator.titanium.util.TiConvert.toBoolean(TiConvert.java:360) [ERROR] : TiApplication: at org.appcelerator.titanium.util.TiConvert.toBoolean(TiConvert.java:390) [ERROR] : TiApplication: at ti.modules.titanium.ui.widget.TiUISwitch.processProperties(TiUISwitch.java:53) [ERROR] : TiApplication: at ti.modules.titanium.ui.widget.listview.ListSectionProxy.populateViews(ListSectionProxy.java:891) [ERROR] : TiApplication: at ti.modules.titanium.ui.widget.listview.TiListView$TiBaseAdapter.getView(TiListView.java:276) [ERROR] : TiApplication: at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:220) [ERROR] : TiApplication: at android.widget.AbsListView.obtainView(AbsListView.java:2405) [ERROR] : TiApplication: at android.widget.ListView.makeAndAddView(ListView.java:1909) [ERROR] : TiApplication: at android.widget.ListView.fillDown(ListView.java:723) [ERROR] : TiApplication: at android.widget.ListView.fillSpecific(ListView.java:1388) [ERROR] : TiApplication: at android.widget.ListView.layoutChildren(ListView.java:1690) [ERROR] : TiApplication: at android.widget.AbsListView.onLayout(AbsListView.java:2201) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:610) [ERROR] : TiApplication: at ti.modules.titanium.ui.widget.listview.TiListView$ListViewWrapper.onLayout(TiListView.java:157) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:853) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) [ERROR] : TiApplication: at android.widget.FrameLayout.onLayout(FrameLayout.java:273) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) [ERROR] : TiApplication: at android.widget.FrameLayout.onLayout(FrameLayout.java:273) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) [ERROR] : TiApplication: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) [ERROR] : TiApplication: at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) [ERROR] : TiApplication: at android.widget.FrameLayout.onLayout(FrameLayout.java:273) [ERROR] : TiApplication: at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2720) [ERROR] : TiApplication: at android.view.View.layout(View.java:16833) [ERROR] : TiApplication: at android.view.ViewGroup.layout(ViewGroup.java:5438) [ERROR] : TiApplication: at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2474) [ERROR] : TiApplication: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2131) [ERROR] : TiApplication: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1233) [ERROR] : TiApplication: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6560) [ERROR] : TiApplication: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:919) [ERROR] : TiApplication: at android.view.Choreographer.doCallbacks(Choreographer.java:710) [ERROR] : TiApplication: at android.view.Choreographer.doFrame(Choreographer.java:645) [ERROR] : TiApplication: at a [INFO] : Process: Sending signal. PID: 25349 SIG: 9 [LiveView] Client disconnected [LiveView] Client connected {noformat}

Comments

  1. Gary Mathews 2018-07-02

    master: https://github.com/appcelerator/titanium_mobile/pull/10148
  2. Samir Mohammed 2018-07-20

    [~gmathews] Using SDK version 7.4.0.v20180718223310 and the test case provided in the description. I get an application crash (no error shown in the console) when choosing an answer and then pressing submit. *Test Environment*
       APPC Studio: 5.0.0.201712081732
       APPC CLI: 7.0.4
       Nexus 5X Emulator (7.1.1)
       Operating System Name: Mac OS High Sierra
       Operating System Version: 10.13
       Node.js Version: 8.9.1
       Xcode 9.2
       
  3. Samir Mohammed 2018-09-20

    *Closing ticket.* On the latest SDK 7.5.0.v20180920040518 the application no longer crashes when clicking on an answer and then pressing submit. *Test Environment* APPC Studio: 5.1.0.201808080937 APPC CLI: 7.0.7-master.1 Nexus 6P (API 23) Operating System Name: Mac OS High Sierra Operating System Version: 10.13.6 Node.js Version: 8.9.1

JSON Source