xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] Java.Lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds #13652

Open Mertsch opened 3 years ago

Mertsch commented 3 years ago

Description

TaskScheduler.UnobservedTaskException event handler catches

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Attempt to invoke virtual method 'void android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable)' on a null object reference) ---> Java.Lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable)' on a null object reference
  at Java.Interop.JniEnvironment+StaticMethods.CallStaticVoidMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <8b3b636835d84984ba4604c1f57b1983>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeVoidMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in <8b3b636835d84984ba4604c1f57b1983>:0 
  at AndroidX.Core.Widget.TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds (Android.Widget.TextView textView, Android.Graphics.Drawables.Drawable start, Android.Graphics.Drawables.Drawable top, Android.Graphics.Drawables.Drawable end, Android.Graphics.Drawables.Drawable bottom) [0x000ba] in D:\a\1\s\generated\androidx.core.core\obj\Release\monoandroid90\generated\src\AndroidX.Core.Widget.TextViewCompat.cs:518 
  at Xamarin.Forms.Platform.Android.ButtonLayoutManager+<>c__DisplayClass30_0.<UpdateImage>b__0 (Android.Graphics.Drawables.Drawable image) [0x0005f] in D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonLayoutManager.cs:356 
  at Xamarin.Forms.Platform.Android.ResourceManager.ApplyDrawableAsync (Xamarin.Forms.Platform.Android.IVisualElementRenderer renderer, Xamarin.Forms.BindableObject bindable, Xamarin.Forms.BindableProperty imageSourceProperty, Android.Content.Context context, System.Action`1[T] onSet, System.Action`1[T] onLoading, System.Threading.CancellationToken cancellationToken) [0x00315] in D:\a\1\s\Xamarin.Forms.Platform.Android\ResourceManager.cs:260 
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Java.Lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable)' on a null object reference
  at Java.Interop.JniEnvironment+StaticMethods.CallStaticVoidMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <8b3b636835d84984ba4604c1f57b1983>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeVoidMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in <8b3b636835d84984ba4604c1f57b1983>:0 
  at AndroidX.Core.Widget.TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds (Android.Widget.TextView textView, Android.Graphics.Drawables.Drawable start, Android.Graphics.Drawables.Drawable top, Android.Graphics.Drawables.Drawable end, Android.Graphics.Drawables.Drawable bottom) [0x000ba] in D:\a\1\s\generated\androidx.core.core\obj\Release\monoandroid90\generated\src\AndroidX.Core.Widget.TextViewCompat.cs:518 
  at Xamarin.Forms.Platform.Android.ButtonLayoutManager+<>c__DisplayClass30_0.<UpdateImage>b__0 (Android.Graphics.Drawables.Drawable image) [0x0005f] in D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonLayoutManager.cs:356 
  at Xamarin.Forms.Platform.Android.ResourceManager.ApplyDrawableAsync (Xamarin.Forms.Platform.Android.IVisualElementRenderer renderer, Xamarin.Forms.BindableObject bindable, Xamarin.Forms.BindableProperty imageSourceProperty, Android.Content.Context context, System.Action`1[T] onSet, System.Action`1[T] onLoading, System.Threading.CancellationToken cancellationToken) [0x00315] in D:\a\1\s\Xamarin.Forms.Platform.Android\ResourceManager.cs:260 <---

Steps to Reproduce

It happens randomly in the background. Seems to be related to navigation (switching pages). Edit: After playing a bit more it especially seems to happen when you navigate from one page to another while it's still being set up. For example: Enter a page, notice immediately (in code) you should be somewhere else and navigate away from the current page which has some buttons with icons on it.

Expected Behavior

No UnobservedTaskException should be thrown.

Actual Behavior

UnobservedTaskException is thrown.

Basic Information

Environment

Show/Hide Visual Studio info ``` Microsoft Visual Studio Professional 2019 Version 16.8.4 VisualStudio.16.Release/16.8.4+30907.101 Microsoft .NET Framework Version 4.8.04084 Installed Version: Professional .ignore 1.2.77 A language service that makes it painless to handle all types of .ignore files such as .gitignore, .tfignore, etc. ASP.NET and Web Tools 2019 16.8.557.25636 ASP.NET and Web Tools 2019 ASP.NET Core Razor Language Services 16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c Provides languages services for ASP.NET Core Razor. ASP.NET Web Frameworks and Tools 2019 16.8.557.25636 For additional information, visit https://www.asp.net/ Azure App Service Tools v3.0.0 16.8.557.25636 Azure App Service Tools v3.0.0 Azure Functions and Web Jobs Tools 16.8.557.25636 Azure Functions and Web Jobs Tools C# Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. File Icons 2.7 Adds icons for files that are not recognized by Solution Explorer IntelliCode Extension 1.0 IntelliCode Visual Studio Extension Detailed Info JetBrains ReSharper 2021.1 EAP 1 Build 211.0.20210127.53750-eap01 JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2021 JetBrains, Inc. Markdown Editor 1.12.253 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown. Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.30924.1 Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE. Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Microsoft Library Manager 2.1.113+g422d40002e.RR Install client-side libraries easily to any web project Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container. Mono Debugging for Visual Studio 16.8.43 (00471f8) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 5.8.1 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ OpenInExplorerCommand Extension 1.0 OpenInExplorerCommand Visual Studio Extension Detailed Info ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info ResXManager 1.49.4013.0 Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid. Smooth Caret 2.0.0 Smooth caret movement effect for the Visual Studio text editor. Smooth Scroll Extension 1.0 Smooth Scroll Extension for Visual Studio 2013, 2015 and 2017 SQL Server Data Tools 16.0.62012.31170 Microsoft SQL Server Data Tools TFS Source Control Explorer Extension 1.0 Visual Studio Extension for Team Foundation Server Source Control Explorer TypeScript Tools 16.0.21016.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd Microsoft Visual F# Tools Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio. Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSColorOutput 2.73 Color output for build and debug windows - https://mike-ward.net/vscoloroutput WiX Toolset Visual Studio Extension 1.0.0.4 WiX Toolset Visual Studio Extension version 1.0.0.4 Copyright (c) .NET Foundation and contributors. All rights reserved. Xamarin 16.8.000.261 (d16-8@bb99248) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 16.8.0.507 (remotes/origin/d16-8@e87b24884) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 16.8.112 (86385a3) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 11.1.0.26 (d16-8/a36ce73) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc Xamarin.iOS and Xamarin.Mac SDK 14.8.0.3 (c51fabee8) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

n/a

Screenshots

n/a

Reproduction Link

n/a

Workaround

Ignoring the exception seems to be OK.

JasonBro commented 3 years ago

I'm getting the same thing. Here's my stack-track from a Samsung, SM-T307U, SM-T307U, 10, 10.0, Tablet.

The first occurrence of this was on the 16th of December 2020, built with:-

<package id="Xamarin.Forms" version="4.7.0.1080" targetFramework="monoandroid10.0" />

The version of Xamarin.Forms did not change for this release of the software, so before this, 4.7.0.1080 had been working correctly with our software. I will try and find out what changed in our software that might have to caused this.

Exception: 
------------------------------
System.AggregateException
A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Attempt to invoke virtual method 'void android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable)' on a null object reference)

------------------------------
Java.Lang.NullPointerException
Attempt to invoke virtual method 'void android.widget.TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable, android.graphics.drawable.Drawable)' on a null object reference
  at Java.Interop.JniEnvironment+StaticMethods.CallStaticVoidMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <6a788f2c787d486583789207282e7d6d>:0 
  at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeVoidMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in <6a788f2c787d486583789207282e7d6d>:0 
  at AndroidX.Core.Widget.TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds (Android.Widget.TextView textView, Android.Graphics.Drawables.Drawable start, Android.Graphics.Drawables.Drawable top, Android.Graphics.Drawables.Drawable end, Android.Graphics.Drawables.Drawable bottom) [0x000c4] in <f65a041d77304375aaef343da8bb6749>:0 
  at Xamarin.Forms.Platform.Android.ButtonLayoutManager+<>c__DisplayClass28_0.<UpdateImage>b__0 (Android.Graphics.Drawables.Drawable image) [0x0005f] in <b8a26c6e6e4e490ea11ef41215895df6>:0 
  at Xamarin.Forms.Platform.Android.ResourceManager.ApplyDrawableAsync (Xamarin.Forms.Platform.Android.IVisualElementRenderer renderer, Xamarin.Forms.BindableObject bindable, Xamarin.Forms.BindableProperty imageSourceProperty, Android.Content.Context context, System.Action`1[T] onSet, System.Action`1[T] onLoading, System.Threading.CancellationToken cancellationToken) [0x00315] in <b8a26c6e6e4e490ea11ef41215895df6>:0 
rachelkang commented 3 years ago

Hi, @Mertsch - thanks for submitting this issue. Would you share your project or a sample project reproducing this issue, so that we can further investigate? Thank you :)

Mertsch commented 3 years ago

@rachelkang Right now I would need to share the source of our App, as I do not have an isolated repo App. This makes it hard for me to share a solution. Since my time is very limited right now I might not get to it.

Hopefully someone else might help?!

PureWeen commented 3 years ago

A lot of the Android image loading code isn't properly awaited which I'm guessing is causing this problem

As a current workaround you might look at delaying the page switch code or detecting pre-page push that you want to go somewhere else