Xamarin.forms: [Android] IPlatformLayout.OnLayout NullReferenceException

Created on 14 Aug 2018  ·  8Comments  ·  Source: xamarin/Xamarin.Forms

MOST AFFECTED OS

SDK 26: 52.4%
SDK 24: 28.6%
SDK 23: 9.5%
SDK 19: 4.8%
Others: 4.8%

Xamarin Exception Stack:
System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00022] in <6b73296523894c3d8d57f5a8e3480a43>:0
  at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00018] in <6b73296523894c3d8d57f5a8e3480a43>:0
  at Android.Views.ViewGroup.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) [0x00008] in <263adecfa58f4c449f1ff56156d886fd>:0
  at (wrapper dynamic-method) System.Object.b1877aae-efaa-4c5e-bbae-15cc687c6a54(intptr,intptr,bool,int,int,int,int)

Thread 329:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Daemons$ReferenceQueueDaemon.run(Daemons.java:150)
2   java.lang.Thread.run(Thread.java:776)

Thread 330:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Object.wait(Object.java:407)
2   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:188)
3   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:209)
4   java.lang.Daemons$FinalizerDaemon.run(Daemons.java:204)
5   java.lang.Thread.run(Thread.java:776)

Thread 331:
0   java.lang.Thread.sleep(Thread.java:-2)
1   java.lang.Thread.sleep(Thread.java:379)
2   java.lang.Thread.sleep(Thread.java:321)
3   java.lang.Daemons$FinalizerWatchdogDaemon.sleepFor(Daemons.java:314)
4   java.lang.Daemons$FinalizerWatchdogDaemon.waitForFinalization(Daemons.java:336)
5   java.lang.Daemons$FinalizerWatchdogDaemon.run(Daemons.java:253)
6   java.lang.Thread.run(Thread.java:776)

Thread 332:
0   dalvik.system.VMRuntime.runHeapTasks(VMRuntime.java:-2)
1   java.lang.Daemons$HeapTaskDaemon.run(Daemons.java:433)
2   java.lang.Thread.run(Thread.java:776)

Thread 347:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Thread.parkFor$(Thread.java:2142)
2   sun.misc.Unsafe.park(Unsafe.java:325)
3   java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
4   java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
5   java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
6   java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
7   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
8   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
9   java.lang.Thread.run(Thread.java:776)

Thread 353:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:356)
2   android.os.Looper.loop(Looper.java:138)
3   android.os.HandlerThread.run(HandlerThread.java:61)

Thread 355:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:356)
2   android.os.Looper.loop(Looper.java:138)
3   android.os.HandlerThread.run(HandlerThread.java:61)

Thread 373:
0   android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
1   android.os.MessageQueue.next(MessageQueue.java:356)
2   android.os.Looper.loop(Looper.java:138)
3   android.os.HandlerThread.run(HandlerThread.java:61)

Thread 379:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Thread.parkFor$(Thread.java:2142)
2   sun.misc.Unsafe.park(Unsafe.java:325)
3   java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
4   java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
5   java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
6   java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
7   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
8   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
9   KE.run
10  java.lang.Thread.run(Thread.java:776)

Thread 383:
0   java.lang.Object.wait(Object.java:-2)
1   com.android.okhttp.okio.AsyncTimeout.awaitTimeout(AsyncTimeout.java:323)
2   com.android.okhttp.okio.AsyncTimeout.-wrap0(AsyncTimeout.java:-1)
3   com.android.okhttp.okio.AsyncTimeout$Watchdog.run(AsyncTimeout.java:286)

Thread 396:
0   java.lang.Object.wait(Object.java:-2)
1   java.lang.Thread.parkFor$(Thread.java:2142)
2   sun.misc.Unsafe.park(Unsafe.java:325)
3   java.util.concurrent.locks.LockSupport.park(LockSupport.java:161)
4   java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2035)
5   java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:413)
6   java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1058)
7   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1118)
8   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
9   KE.run
10  java.lang.Thread.run(Thread.java:776)

Thread 728:
0   java.lang.Object.wait(Object.java:-2)
1   com.android.okhttp.ConnectionPool.performCleanup(ConnectionPool.java:305)
2   com.android.okhttp.ConnectionPool.runCleanupUntilPoolIsEmpty(ConnectionPool.java:242)
3   com.android.okhttp.ConnectionPool.-wrap0(ConnectionPool.java:-1)
4   com.android.okhttp.ConnectionPool$1.run(ConnectionPool.java:97)
5   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
6   java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
7   java.lang.Thread.run(Thread.java:776)

No code to reproduce
Latest XF

has-stacktrace Android needs-info ❓ needs-repro ❔ bug

Most helpful comment

I have faced the same issue through Xamarin.Forms 4.4.0.991477:

  • Running on Android 9 through a Samsung Galaxy S9 Genymotion simulator (Version 3.0.4 | Revision 20191213-90e54e2).
  • Android SDK 28.

Backtrace:

android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0002b] in <a38b08ed6ae34fcca788cdc23b3fac01>:0
     at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00025] in <a38b08ed6ae34fcca788cdc23b3fac01>:0
     at Android.Views.ViewGroup.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) [0x00009] in <11f101b564894ca7af6c482ddc51c698>:0
       at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.34(intptr,intptr,bool,int,int,int,int)
       at crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout(Native Method)
       at crc643f46942d9dd1fff9.PlatformRenderer.onLayout(PlatformRenderer.java:63)

All 8 comments

Offset maps to here.

@paleicikas we can't just add a null check here. We'll have to see why it's null. Could you submit a reproduction?

unfortunately no reproduction available (large project, unknown location), thanks

I'm not sure if we'll be able to get that far with this one. The permutation of things that could cause this include a lot of things you might be doing in your project that just aren't supported ways of doing something.

There are a few issues like this that have been fixed in the past
There's a thread here
https://forums.xamarin.com/discussion/58557/page-throws-an-error-on-android-i-want-to-know-what-causes-this-error

That talks about some issues people have seen.

Some last couple notes

  • 3.2 added a few additional lifecycle changes to Android so perhaps that will resolve
  • If there are any other tidbits about your application flow that we could try out that would be helpful. Are you switching out MainPages? Removing Tabs? Is it masterdetails? Do you have any additional event logging with your tool that talks about application flow before this?

Hmm, I'm seeing this issue in my solution at the moment. Have upgraded from Xamarin Form 2.4 to 3.2 and also added in MvvmCross. Will go and have a look at that thread linked to above to see if that helps.

no repro project in a month. closing. reopen when you have a repro project to attach. thanks

I have faced the same issue through Xamarin.Forms 4.4.0.991477:

  • Running on Android 9 through a Samsung Galaxy S9 Genymotion simulator (Version 3.0.4 | Revision 20191213-90e54e2).
  • Android SDK 28.

Backtrace:

android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0002b] in <a38b08ed6ae34fcca788cdc23b3fac01>:0
     at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00025] in <a38b08ed6ae34fcca788cdc23b3fac01>:0
     at Android.Views.ViewGroup.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) [0x00009] in <11f101b564894ca7af6c482ddc51c698>:0
       at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.34(intptr,intptr,bool,int,int,int,int)
       at crc643f46942d9dd1fff9.PlatformRenderer.n_onLayout(Native Method)
       at crc643f46942d9dd1fff9.PlatformRenderer.onLayout(PlatformRenderer.java:63)

We have this too on occassion. Stacktrace comes from our AppCenter instance.

  • OS: Android 8.1.0
  • Device: TC57
  • Xamarin.Forms: 4.6.0.726
IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
System.NullReferenceException: Object reference not set to an instance of an object
IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b)
ViewGroup.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)
(wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.40(intptr,intptr,bool,int,int,int,int)
Was this page helpful?
0 / 5 - 0 ratings