Xamarin.Forms
Xamarin.Forms copied to clipboard
[Bug] Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'boolean android.view.View.isLayoutDirectionInherited()' on a null object reference'
Description
Hi team,
we have facing the same kind of issue, in the OnMeasure Method
Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'boolean android.view.View.isLayoutDirectionInherited()' on a null object reference'
call stack Unhandled exception - Java.Lang.NullPointerException: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
--- End of managed Java.Lang.NullPointerException stack trace ---
java.lang.NullPointerException: Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewGroup.dispatchCollectViewAttributes(ViewGroup.java:1687)
at android.view.ViewRootImpl.collectViewAttributes(ViewRootImpl.java:2698)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3263)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2669)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10092)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1010)
at android.view.Choreographer.doCallbacks(Choreographer.java:809)
at android.view.Choreographer.doFrame(Choreographer.java:744)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:995)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:247)
at android.app.ActivityThread.main(ActivityThread.java:8656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130).
could you please provide the solution to resolve the issue
Expected Behavior
Actual Behavior
Basic Information
- Version with issue: issue reproduce in android platform xamarin form version: 4.5.0.617
Environment
Show/Hide Visual Studio info
Build Logs
Screenshots
Reproduction Link
Workaround
Could you attach a small sample where reproduce the issue?
Hi @jsuarezruiz,
Currently, we are creating a simple sample to replicate the issue. Once, we have prepared the sample. we will update the task.
Regards, SaiGanesh Sakthivel
Hi @jsuarezruiz,
We are using the custom renderer in our sample. The reported crash occurs randomly. It is hard to replicate in a simple sample. could you please share the possible null check to overcome the reported crash?
Regards, SaiGanesh Sakthivel
This is also happening for us. It is a hard crash and cannot use try catch to overcome this. I have just 1 available report. Cannot replicate the issue. Android 11, realme 8i.
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout FormsViewGroup.java, line 36 Java.Lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.isLayoutDirectionInherited()' on a null object reference
JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args)
JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
FormsViewGroup.MeasureAndLayout (System.Int32 widthMeasureSpec, System.Int32 heightMeasureSpec, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
VisualElementTracker.UpdateLayout ()
VisualElementRenderer`1[TElement].UpdateLayout ()
VisualElementRenderer`1[TElement].UpdateLayout (System.Collections.Generic.IEnumerable`1[T] children)
VisualElementRenderer`1[TElement].OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
PageRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
FormsViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V (_JniMarshal_PPZIIII_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.Boolean p0, System.Int32 p1, System.Int32 p2, System.Int32 p3, System.Int32 p4)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.View.isLayoutDirectionInherited()' on a null object reference
android.view.ViewGroup.resolveDrawables ViewGroup.java:7939
android.view.ViewGroup.resolveDrawables ViewGroup.java:7940
android.view.ViewGroup.resolveDrawables ViewGroup.java:7940
android.view.ViewGroup.resolveDrawables ViewGroup.java:7940
android.view.ViewGroup.resolveDrawables ViewGroup.java:7940
android.view.ViewGroup.resolveDrawables ViewGroup.java:7940
android.view.ViewGroup.resolveDrawables ViewGroup.java:7940
android.view.View.resolveRtlPropertiesIfNeeded View.java:20294
android.view.ViewGroup.resolveRtlPropertiesIfNeeded ViewGroup.java:7846
android.view.View.measure View.java:25959
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout FormsViewGroup.java:36
crc643f46942d9dd1fff9.PageRenderer.n_onLayout(Native Method)
crc643f46942d9dd1fff9.PageRenderer.onLayout PageRenderer.java:72
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout FormsViewGroup.java:37
crc64720bb2db43a66fe9.NavigationPageRenderer.n_onLayout(Native Method)
crc64720bb2db43a66fe9.NavigationPageRenderer.onLayout NavigationPageRenderer.java:65
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
com.xamarin.forms.platform.android.FormsViewGroup.measureAndLayout FormsViewGroup.java:37
crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout(Native Method)
crc643f46942d9dd1fff9.PlatformRenderer.onLayout PlatformRenderer.java:55
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.widget.RelativeLayout.onLayout RelativeLayout.java:1103
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.widget.FrameLayout.layoutChildren FrameLayout.java:332
android.widget.FrameLayout.onLayout FrameLayout.java:270
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.widget.FrameLayout.layoutChildren FrameLayout.java:332
android.widget.FrameLayout.onLayout FrameLayout.java:270
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.widget.FrameLayout.layoutChildren FrameLayout.java:332
android.widget.FrameLayout.onLayout FrameLayout.java:270
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.widget.LinearLayout.setChildFrame LinearLayout.java:1841
android.widget.LinearLayout.layoutVertical LinearLayout.java:1673
android.widget.LinearLayout.onLayout LinearLayout.java:1582
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.widget.FrameLayout.layoutChildren FrameLayout.java:332
android.widget.FrameLayout.onLayout FrameLayout.java:270
com.android.internal.policy.DecorView.onLayout DecorView.java:878
android.view.View.layout View.java:23310
android.view.ViewGroup.layout ViewGroup.java:6539
android.view.ViewRootImpl.performLayout ViewRootImpl.java:3973
android.view.ViewRootImpl.performTraversals ViewRootImpl.java:3372
android.view.ViewRootImpl.doTraversal ViewRootImpl.java:2337
android.view.ViewRootImpl$TraversalRunnable.run ViewRootImpl.java:9039
android.view.Choreographer$CallbackRecord.run Choreographer.java:1179
android.view.Choreographer.doCallbacks Choreographer.java:1002
android.view.Choreographer.doFrame Choreographer.java:899
android.view.Choreographer$FrameDisplayEventReceiver.run Choreographer.java:1164
android.os.Handler.handleCallback Handler.java:938
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loop Looper.java:261
android.app.ActivityThread.main ActivityThread.java:8314
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:632
com.android.internal.os.ZygoteInit.main ZygoteInit.java:1049
Getting the similar exception: Java.Lang.NullPointerException Message=Attempt to invoke virtual method 'boolean android.view.View.isInLayout()' on a null object reference. Happens when updating the following ViewModel property:
public ImageSource CoverPhotoSource { get { return _coverPhotoSource; } set { if (value != _coverPhotoSource) { _coverPhotoSource = value; OnPropertyChanged("CoverPhotoSource"); } } } private ImageSource _coverPhotoSource = null;
Bound to following XAML:
<Image x:Name="coverPhoto" Source="{Binding CoverPhotoSource}" Aspect="AspectFill" HorizontalOptions="FillAndExpand"></Image>
Is some progress in this topic? I can say, this causes 60% of our app crashes.
Xamarin Forms 5.0.0.2515
I bring more information about the devices this is happening on. Looks like mostly it's Galaxy & Android 13 combination.
POCO X3 Pro Android 11 Galaxy S20 Android 13 Galaxy Z Fold4 Android 13 Galaxy S22+ Android 13 Galaxy Tab S7+ 5G Android 13 Galaxy A32 5G Android 13 Galaxy A52 Android 13 Galaxy A53 5G Android 13 Galaxy S21 5G Android 13 Galaxy A23 Android 13 Galaxy S20 Ultra 5G Android 13 Galaxy XCover 5 Android 13 Galaxy A52s 5G Android 13 Galaxy A22s 5G Android 13 Galaxy A72 Android 13 Galaxy A13 Android 13