Bug 27974 - ListView LongPress Exception
Summary: ListView LongPress Exception
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.0
Hardware: PC All
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-03-12 13:35 UTC by Wessel Oosthuizen
Modified: 2017-01-04 00:51 UTC (History)
16 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Wessel Oosthuizen 2015-03-12 13:35:17 UTC
Using android galaxy s3. I have a listview for which the datatemplate is a textcell. If I have no contextmenu items defined, and press on multiple list items, it throws an exception and the app crashes. So I have no context items defined, I longpress the first list item, then long press the second, it crashes. Exception below:

    03-12 11:56:56.201 E/mono-rt (18044): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
    03-12 11:56:56.201 E/mono-rt (18044):   at Xamarin.Forms.Platform.Android.CellAdapter.set_ContextView (Android.Views.View value) [0x00000] in <filename unknown>:0 
    03-12 11:56:56.201 E/mono-rt (18044):   at Xamarin.Forms.Platform.Android.CellAdapter.HandleContextMode (Android.Views.View view, Int32 position) [0x00000] in <filename unknown>:0 
    03-12 11:56:56.201 E/mono-rt (18044):   at Xamarin.Forms.Platform.Android.CellAdapter.OnItemLongClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x00000] in <filename unknown>:0 
    03-12 11:56:56.201 E/mono-rt (18044):   at Android.Widget.AdapterView+IOnItemLongClickListenerInvoker.n_OnItemLongClick_Landroid_widget_AdapterView_Landroid_view_View_IJ (IntPtr jnienv, IntPtr native__this, IntPtr native_parent, IntPtr native_view, Int32 position, Int64 id) [0x00019] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/9e05e39f/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Widget.AdapterView.cs:337 
    03-12 11:56:56.201 E/mono-rt (18044):   at (wrapper dynamic-method) object:d230536c-bfc0-4502-a64d-7e68792208ce (intptr,intptr,intptr,intptr,int,long)
Comment 1 Parmendra Kumar 2015-03-13 07:00:16 UTC
I have checked this issue and I am able to reproduce this issue. To reproduce this issue I have followed steps:

1. Open Xamarin.Forms sample 'WorkingWithListview' in XS/VS
2. Set Android as startup project and deploy to device.
3. LongPress on multiple list items 

Actual Result: Application throws an exception and the app crashes.

Note: On iOS its working fine.

Screencast: http://www.screencast.com/t/5NAtQbXnI

Application Output: https://gist.github.com/Parmendrak/741948dfe0d35611e0fc
DeviceLog:https://gist.github.com/Parmendrak/e149d7f3bbb6059e550a
BuildOutput:https://gist.github.com/Parmendrak/ac0bd5319b82d3b20a16
IDELog:https://gist.github.com/Parmendrak/d0e2dc94d26c14f20126

Xamarin.Form: 1.4.0.6341 and 1.4.1.6342-pre1

Environment info:
=== Xamarin Studio ===

Version 5.8 (build 443)
Installation UUID: 1a096c6f-0678-402e-89b2-a2c10f7e80e4
Runtime:
	Mono 3.12.1 ((detached/b7764aa)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010000

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.8.0.2 (Business Edition)
Hash: ccfcd59
Branch: 
Build date: 2015-03-10 02:20:32-0400

=== Xamarin.Android ===

Version: 4.20.0.37 (Business Edition)
Android SDK: /Users/360_macmini/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 1.10.0.21 (Business Edition)

=== Build Information ===

Release ID: 508000443
Git revision: 73883239470cbe8e261c94d95f7c3d0452fd393b
Build date: 2015-03-10 07:22:51-04
Xamarin addins: a2ff7b617f09d9c45d8bbf3d010b5db0d7d36100

=== Operating System ===

Mac OS X 10.9.4
Darwin ShrutiMac.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 2 Michael Rumpler 2015-03-17 09:34:51 UTC
I get the same exception. Tested on a Sony Xperia Z1 Compact and a Google Nexus 10.

Reproducible with this in your App.cs:

		public App()
		{

			var l = new ListView();
			l.ItemsSource = new[] { "One", "Two", "Three", "Four", "Five"};
			l.ItemTemplate = new DataTemplate(() => {
				var cell = new TextCell();
				cell.SetBinding(TextCell.TextProperty, ".");
				return cell;
			});

			// The root page of your application
			MainPage = new ContentPage
			{
				Content = new StackLayout
				{
					Children = {
						l
					}
				}
			};
		}
Comment 3 Ray Shi 2015-03-20 01:00:47 UTC
I also experienced this on both Samsung tablets and mobile phones.
After investigation I found this is caused by the update of Xamarin.Forms.
In my case, with the current latest stable version 1.4.0.6341 you will have this bug in Android platform however if you downgrade your Xamarin.Forms to 1.3.4.6332 then this bug disappeared. 

BUT with the version 1.3.4.6332 I found all entry controld inside the cells won't work anymore.

Also tried on the 1.4.0.6341(prerelease), still has this issue.
Comment 4 David Catteuw 2015-04-03 08:40:50 UTC
My (Android) application suffers from this issue too...
I'm running Forms version 1.4.1 stable.
Please try to fix this asap, Xamarin team!
Comment 5 Parmendra Kumar 2015-04-03 09:56:04 UTC
I am getting same behavior with Xamarin.Forms version: 1.4.2-pre2.

Screencast: http://www.screencast.com/t/HvgLSjOm
Comment 6 NMackay 2015-04-09 06:11:41 UTC
Hi,

Also getting this behavior in forms 1.4.1 stable on hardware and emulators.
Comment 7 Jason Smith [MSFT] 2015-04-09 16:52:35 UTC
Should be fixed in 1.4.3-pre1
Comment 8 Parmendra Kumar 2015-04-23 11:19:03 UTC
I have checked this issue with Xamarin.Forms 1.4.3-pre1 and now its working fine at my end.

Hence closing this issue.
Comment 9 tim.ahrentlov 2015-06-07 15:04:52 UTC
When can we expect to receive this fix in a stable release ? It's been months since this bug was reported.

If no stable release is imminent, then how do we code around it and preserve context-actions?

The code-around suggested in this thread   http://forums.xamarin.com/discussion/35704/listview-longpress-exception works, but context actions are effectively disabled.
Comment 10 rfreschi 2017-01-04 00:51:21 UTC
I'm seeing this after an item has been long pressed into a ContextAction mode and then the list is scrolled. List only has 10 items.

Only happens if cachingStrategy is RecycleElement , not RetainElement

Android 6.0.1
Xamarin.Forms 2.3.3.175

Error:
[MonoDroid] System.NullReferenceException: Object reference not set to an instance of an object.
[MonoDroid]   at Xamarin.Forms.Platform.Android.CellAdapter.set_ContextView (Android.Views.View value) [0x00012] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\CellAdapter.cs:67 
[MonoDroid]   at Xamarin.Forms.Platform.Android.ListViewAdapter.GetView (System.Int32 position, Android.Views.View convertView, Android.Views.ViewGroup parent) [0x000e8] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Renderers\ListViewAdapter.cs:218 
[MonoDroid]   at Android.Widget.BaseAdapter.n_GetView_ILandroid_view_View_Landroid_view_ViewGroup_ (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 position, System.IntPtr native_convertView, System.IntPtr native_parent) [0x0001a] in /Users/builder/data/lanes/3511/501e63ce/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Widget.BaseAdapter.cs:443 
[MonoDroid]   at (wrapper dynamic-method) System.Object:ea63dbd8-d509-43e4-b2f5-a3a725ab05ae (intptr,intptr,int,intptr,intptr)