Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18824] Android: ListView crashes app when scrolled to end of list

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2015-05-13T07:42:14.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.1.0
Componentsn/a
Labelsandroid, crash, listview
ReporterAlex Bernier
AssigneeAshraf Abu
Created2015-04-10T21:05:31.000+0000
Updated2015-06-04T01:17:57.000+0000

Description

ListView is crashing when reaching the end of the list. This same test case works without crashing with Ti SDK 4.0.0.Beta2. Steps to reproduce:

Load code below with Ti SDK 4.1.0.v20150410061234

Tap the "Append 10 items" button

Scroll all the way to the bottom

Observer app crash

Test case:
var win = Ti.UI.createWindow({
	backgroundColor : "#ffffff",
	layout : "absolute"
});

win.open();

var appendButton = Ti.UI.createButton({
	title : "Append 10 items",
	height : "10%",
	top : "5%"
});

appendButton.addEventListener("click", function() {
	appendData();
});

win.add(appendButton);

var screenWidth = Ti.Platform.displayCaps.platformWidth;

var listSection = Ti.UI.createListSection();

var listView = Ti.UI.createListView({
	backgroundColor : "#cccccc",
	top : "20%",
	height : "80%",
	templates : {
		"photoWithCaption" : {
			properties : {
				layout : "vertical",
				height : Ti.UI.SIZE
			},
			childTemplates : [{
				type : "Ti.UI.ImageView",
				bindId : "photo",
				properties : {
					height : screenWidth,
					width : screenWidth,
					preventDefaultImage : true
				}
			}, {
				type : "Ti.UI.TextArea",
				bindId : "caption",
				properties : {
					backgroundColor : "#ffffff",
					height : Ti.UI.SIZE,
					left : 10,
					right : 10,
					editable : false,
					scrollable : false
				}
			}]
		}
	},
	defaultItemTemplate : "photoWithCaption"
});

listView.setSections([listSection]);

win.add(listView);

function appendData() {
	var data = [];

	for (var i = 0; i < 10; i++) {
		var text = "This a caption #" + (i + 1) + ", and it may disappear when an append of new data happens on the parent ListView.";

		data.push({
			template : "photoWithCaption",
			photo : {
				image : "http://thecatapi.com/api/images/get?format=src&type=jpg&size=small"
			},
			caption : {
				attributedString : Titanium.UI.createAttributedString({
					text : text,
					attributes : [{
						type : Ti.UI.ATTRIBUTE_FONT,
						value : {
							font : {
								fontSize : 14
							}
						},
						range : [0, text.length]
					}, {
						type : Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
						value : "#000000",
						range : [0, text.length]
					}]
				})
			}
		});
	}

	listSection.appendItems(data);
}
Stack trace:
04-10 13:52:35.211: E/TiApplication(19289): (main) [30186,32990] Sending event: exception on thread: main msg:java.lang.NullPointerException: Attempt to read from field 'java.lang.Object android.util.Pair.second' on a null object reference; Titanium 4.1.0,2015/04/10 06:13,29ba994
04-10 13:52:35.211: E/TiApplication(19289): java.lang.NullPointerException: Attempt to read from field 'java.lang.Object android.util.Pair.second' on a null object reference
04-10 13:52:35.211: E/TiApplication(19289): 	at ti.modules.titanium.ui.widget.listview.TiListView$1.onScrollStateChanged(TiListView.java:337)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.widget.AbsListView.reportScrollStateChange(AbsListView.java:4335)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.widget.AbsListView$FlingRunnable.endFling(AbsListView.java:4466)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4601)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.view.Choreographer.doCallbacks(Choreographer.java:580)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.view.Choreographer.doFrame(Choreographer.java:549)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.os.Handler.handleCallback(Handler.java:739)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.os.Handler.dispatchMessage(Handler.java:95)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.os.Looper.loop(Looper.java:135)
04-10 13:52:35.211: E/TiApplication(19289): 	at android.app.ActivityThread.main(ActivityThread.java:5254)
04-10 13:52:35.211: E/TiApplication(19289): 	at java.lang.reflect.Method.invoke(Native Method)
04-10 13:52:35.211: E/TiApplication(19289): 	at java.lang.reflect.Method.invoke(Method.java:372)
04-10 13:52:35.211: E/TiApplication(19289): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-10 13:52:35.211: E/TiApplication(19289): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
04-10 13:52:35.234: E/AndroidRuntime(19289): FATAL EXCEPTION: main
04-10 13:52:35.234: E/AndroidRuntime(19289): Process: blah, PID: 19289
04-10 13:52:35.234: E/AndroidRuntime(19289): java.lang.NullPointerException: Attempt to read from field 'java.lang.Object android.util.Pair.second' on a null object reference
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at ti.modules.titanium.ui.widget.listview.TiListView$1.onScrollStateChanged(TiListView.java:337)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.widget.AbsListView.reportScrollStateChange(AbsListView.java:4335)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.widget.AbsListView$FlingRunnable.endFling(AbsListView.java:4466)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4601)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.view.Choreographer.doCallbacks(Choreographer.java:580)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.view.Choreographer.doFrame(Choreographer.java:549)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.os.Handler.handleCallback(Handler.java:739)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.os.Handler.dispatchMessage(Handler.java:95)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.os.Looper.loop(Looper.java:135)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at android.app.ActivityThread.main(ActivityThread.java:5254)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at java.lang.reflect.Method.invoke(Native Method)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at java.lang.reflect.Method.invoke(Method.java:372)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
04-10 13:52:35.234: E/AndroidRuntime(19289): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Comments

  1. Neeraj Gupta 2015-04-13

    So your test case works with 4.0.0 SDK but not with 4.1.0 SDK? Note that 4.1.0 SDK is a a CI build and not supported officially.
  2. Alex Bernier 2015-04-13

    [~ngupta] You got it; works in 4.0.0.Beta2. So, maybe this ticket isn't important at the moment, but I noticed it and had a test case ready for another ticket, so I just filed it.
  3. Neeraj Gupta 2015-04-13

    Thank you for filing this issue. We would definitely look at it but it is not the high priority right now.
  4. Alex Bernier 2015-04-13

    Agreed, and no problemo. Good luck with the release! 4.0.0 looks great.
  5. Alex Bernier 2015-05-12

    Submitted a pull request for this. Tested on Nexus 6.
  6. Chee Kiat Ng 2015-05-12

    PR: https://github.com/appcelerator/titanium_mobile/pull/6837
  7. Ashraf Abu 2015-05-13

    [~abernier] PR accepted and merged. Thank you!
  8. Alex Bernier 2015-05-13

    Great news! Thank you!
  9. Lokesh Choudhary 2015-06-04

    Verified the fix. The listview does not crash the app . Closing. Environment: Appc Studio : 4.1.0.201505071004 Ti SDK : 4.1.0.v20150602140423 CLI : 4.0.1 Alloy : 1.6.0 MAC Yosemite : 10.10.3 Appc npm : 4.0.0 Appc CLI : 4.0.1 Node: v0.10.37 Nexus 5 - Android 5.1.1

JSON Source