简体   繁体   中英

Xamarin.Forms App crashes when clicking on Entry, returns “NullReferenceException”

(Problem is solved, creating this since the solution is not online)

When clicking on Entry, the keyboard pops up on the Android emulator and then the app crashes with a NullReferenceException, object not found.

Initially I thought it was a problem in my ViewModel due to the Entry having a Binding to an object in the ViewModel.

I then came to the conclusion that you cannot Bind Entries to ViewModels to both display and update properties of an object, since I couldn't find any clear cut examples of this online. You have to use a button/event that applies the properties to Entry.text or updates the object property with Entry.text.

I fixed this so my Entry had no bindings and the problem still occurred even using a fresh Entry on a fresh page. I lost the stacktrace but it began by saying something along the lines of "xamarin.forms.grid.NumberOfUnsetRows..."

I then remembered that I had attempted to create a custom Entry renderer awhile ago, but deleted the files. This messed up the code behind that created Entries.

Solution: Reinstall Xamarin.Forms Nuget Package. This undid the damage from the custom Entry

Reinstall Xamarin.Forms Nuget Package. This undid the damage from the custom Entry

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM