所以我正在编写一个Xamarin
应用程序,我已经构建了一个CustomRenderer
现在我的方法:
horizontalScrollView.ScrollTo(this.Width, 0);
不断抛出异常:
System.ArgumentException:'jobject'不能是IntPtr.Zero。 10-21 12:10:41.898 E / AndroidRuntime(15053):参数名称:jobject 10-21 12:10:41.898 E / AndroidRuntime(15053):位于/ Users / builder / data / lanes / 2185 / 53fce373 / source / monodroid / src中的Android.Runtime.JNIEnv.CallIntMethod(intptr,intptr)[0x00010] /Mono.Android/src/Runtime/JNIEnv.g.cs:378 10-21 12:10:41.898 E / AndroidRuntime(15053):在Android.Views.View.get_Width()
所以看看异常,从我的断点开始,我发现问题是,当我将鼠标悬停在this.Width
上时,我得'jobject' must not be IntPtr.Zero
而不是integer
,所以我尝试防御性地编码这个和做:
if (this.Width != IntPtr.Zero)
{
horizontalScrollView.ScrollTo(this.Width, 0);
}
但这不会编译并给我错误:
运算符'!='不能应用于'int'类型的操作数 '的IntPtr'
所以我的问题是。有没有办法检查value type
是否等于IntPtr.Zero
?
答案 0 :(得分:2)
由于您正在使用自定义渲染器,我假设您使用的是Xamarin.Forms。
您无法在此处查看Width
。 Write a question here
Write another question here
Write the third question here
由Xamarin.Forms内部设置。您通常无法访问错误的指针。因此,您无法在那里看到它,但是当您访问A
属性时收到错误,因为它在内部使用该指针。
导致此错误的原因有两种:
答案 1 :(得分:0)
也许您必须检查作业而不是反对属性值' width'。