System.NullReferenceException: Object reference not set to an instance of an object in Entry Object

Good Morning!

When using methods like Trim () or Length in an Entry object I am getting the message: "System.NullReferenceException: Object reference not set to an instance of an object"

The following example:
if (TxtName.Text.Trim() == "")
{}
or
if (TxtName.Text.Length == 0)
{}

How can I get out of error?

Tagged:

Posts

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    I'm going to suggest you stop. Xamarin is an eco-system for cross-platform development. It is not a good environment to start learning basic coding in. You pretty much need to have already learned C# and have some foundation development skills before getting into advanced concepts like developing across multiple platforms.

    In other words... If you haven't learned to code in just one environment like Windows yet - its not realistic to think you're going to learn to code across three environments at once. You have to learn the basics first. Then take those skills and learn how to apply them to 3-4 operating systems in a compatible fashion.

  • jmenezesjmenezes Member ✭✭

    Thank you ClintStLaurent!

    Ok, how else can I solve this problem, because apparently it should work, once the method is available?

    Is there anything I can do? I'm a beginner...

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    When you say

    Its my first time using Xamarin.

    If you really mean

    Its my first time doing any coding at all

    Then stop and don't get into Xamarin at all yet. First you need to learn C# which is the language all your logic and actual 'code' will be written in. Xamarin is an eco-system that your code operates within so that the same code can run on iOS, Android, UWP, MacOS and Tizen without having to create separate solutions for each platform. But if you can't first write code - any code - then it does you no good to try to figure out cross-platform deployment.

    Once you are at least somewhat comfortable in C# then look into MVVM design. It is the foundation concept that any app in the last 15 years should be based on, whether that's a Windows WPF program or a Xamarin cross-platform app. If you have no experience with MVVM design... no experience with databinding code to UI... etc. etc. then you need to first get a handle on that.

    Then realize you can't just jump into make your "goal application" as your first project. Your first application can't be an entire inventory and ordering system for your uncle's restaurant, or scheduling app for your sisters delivery service.

    You have to start with building a bird house... then a dog house... then an outhouse... shed... garage... Before you try to build a 3 story apartment building. You have to apply that same "start small and learn" approach to software development. You start by building small apps alike alarm clocks and mortgage calculators, and work up from there learning UI development, OOP and other basics along the way. Then you take those skills to your next bigger project. In other words you have to learn how to be a coder before you can be a software architect.

    When you're ready to start designing an intermediately complex app just tackle one issue at a time in a "Sandbox" or R&D app.
    Start with the first basic need: People
    That's not Xamarin in any way. Just define a Person class. And then inherit from that for a User class. And you'll want a Rights class to be the permissions for that User object.

    Then probably some type of grouping... whether its groups of people or groups of things. Learn how to work with collections of objects.

    But learn each of your bullet points one at a time in a little R&D app before you try to take on putting them all together. You need to understand them as a single thing before you can architect how they will interact.

    In the end... 90% of of the typical app has nothing to do with Xamarin. Its all basic-to-intermediate C#, application architecture and design that would be the same in Xamarin, WinForms, WPF, Android, ...

  • jmenezesjmenezes Member ✭✭

    Thank you for the informations ClintStLaurent!

    I will change my strategy ...

Sign In or Register to comment.