Xamarin "is trying to call the virtual method" void android.view.View.unFocus (android.view.View) "on the link with a null object"

I am developing an application using Xamarin.Forms for cross-platform use. I recently upgraded Xamarin Studio on Mac along with updating NuGet packages.

Now I get this error: I'm trying to call the virtual method void android.view.View.unFocus (android.view.View) 'on the reference of the null object. (See stack table below)

This happens when switching from (or re-rendering) to any page except the root view. I do not believe that I have changed any part of my navigation or page rendering.

I apologize if this is somewhat vague, it can be seen from the stack trace that this does not start with my code (in any traceable way). And I'm not sure where to start debugging. Any advice would be very helpful!

Stack trace

--- End of managed Java.Lang.NullPointerException stack trace --- java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.unFocus(android.view.View)' on a null object reference at android.view.ViewGroup.removeViewInternal(ViewGroup.java:4937) at android.view.ViewGroup.removeViewAt(ViewGroup.java:4899) at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1540) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595) at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:757) at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2355) at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2146) at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2098) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2008) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:710) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7224) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

EDIT: This only happens on Android.

EDIT: Additional Information: This occurs mainly when Navigation.PushAsync or Navigation.PopAsync is called (including pressing the user back button).

Here is the simplest example of this in my application: Starting from the main screen, the user can take actions to go to the QR code scan page. This QR code contains information about the load this driver will supply. After scanning, I save the information and bring the scan page out of the navigation, and then automatically pop it onto the loading screen. After downloading the data, I push them to the list of information they need. (So, now in the navigation stack there is [main, loading_screen, list_view]). If at this moment any function Navigation.PopAsync (or PushAsync) is called, the application is disconnected.

+6
source share
2 answers

Solution found. The simple answer: I didn’t properly manipulate the navigation stack. According to VincentH_NET's answer, I would have to do what I originally tried to do, but due to an error in Xamarin I cannot. Here is the situation:

The application starts only from the main page in the navigation stack, which I will denote with M

[ M

When interacting with the user, I first push the loading screen, indicated by L , onto the navigation stack, while I am preparing the barcode scan page.

[ M, L

Once the scan page is ready, I automatically drag the user forward, leaving the navigation stack as follows:

[ M, L, S

The user now scans a QR code containing search information. After they successfully scan the code, I bring them back to the boot screen (which is now reassigned to the boot screen when I make server requests for my data).

[ M, L

After I downloaded the relevant information from the QR code, I click them in the form of a list of data, page D

[ M, L, D

At this point, I tried to remove the L loading page from the navigation stack using Navigation.RemovePage(); , since the download page is no longer needed and will be confused if the user clicks the back button to see the download screen, which is not loading anything. I wanted a navigation stack that looked like this:

[ M, D

But instead, it seems that deleting my page damaged the navigation stack, which led to the errors I experienced.

My solution now is to instead of trying to remove the download page from the stack, to automatically load the download page from the stack if it does not actually load anything.

PS if anyone has a deeper understanding of this problem or is better than best practice for these types of user interfaces, I would love to hear your answers.

+2
source

This is a confirmed error in Xamarin Forms 2.3.3.193:

Error 53179 - PopAsync crashes after RemovePage when updating support packages to 25.1.1

What you did was not wrong; however your answer is a valid solution.

+4
source

Source: https://habr.com/ru/post/1015158/


All Articles