Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:00:23+00:00 2026-06-17T13:00:23+00:00

In this event handler: public static void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args) { DateTimeOffset timeStampUTC

  • 0

In this event handler:

        public static void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
        {
            DateTimeOffset timeStampUTC = args.Position.Coordinate.Timestamp.ToUniversalTime();
            DateTimeOffset timeStampLocal = timeStampUTC.LocalDateTime;
            DateTimeOffset dateTimeStampUTC = timeStampUTC.DateTime;
            RecordLocation(args.Position.Coordinate.Latitude, args.Position.Coordinate.Longitude,    
            args.Position.CivicAddress.City, args.Position.CivicAddress.State, dateTimeStampUTC, timeStampLocal);
        }

…I’m getting a Null Reference Exception because args.Position.CivicAddress is null (the rest of the args passed to RecordLocation() are valid). I reckon sometimes Position will be null, and sometimes it won’t. What can I do to let the times when no City or State is found pass through unabated? I tried to make those strings in RecordLocation()‘s definition nullable, but that won’t compile.

Do I need to check CivicAddress for null and create an overloaded version of my RecordLocation() method, or is there another way to handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:00:25+00:00Added an answer on June 17, 2026 at 1:00 pm

    What can I do to let the times when no City or State is found pass through unabated?

    You just need to check it. For example:

    if (args.Position != null && args.Position.CivicAddress != null)
    {
        // Now you can use args.Position.CivicAddress.State safely
    }
    

    If you want to do lots of things with args.Position, you quite possibly want one “outer” if statement – quite possibly with a local variable to simplify things:

    var position = args.Position;
    if (position != null)
    {
        if (position.CivicAddress != null)
        {
            // Use properties of position.CivicAddress
        }
        // Assuming Coordinate is nullable to start with, of course...
        if (position.Coordinate != null)
        {
            // ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Evil or not evil? public static void Raise(this EventHandler handler, object sender, EventArgs args)
I have this code for an event handler: rbM.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton
I have public delegate void AdministrationEventHandler(object sender, AdministrationEventArgs e); public static event AdministrationEventHandler MainAdministrationEventHandler;
I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public:
I have declared a generic event handler public delegate void EventHandler(); to which I
In maine, on my button click event handler I do: private void addIconButton_Click(object sender,
In this following excerpt from an example on msdn: public static void StartListening() {
Context I have this piece of Java Code btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent
I have an event handler set up using plain javascript like this: myElement.addEventListener('drop', handleDrop,
I've seen this done inside of an event handler directly behind the .xaml file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.