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 7735315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:28:16+00:00 2026-06-01T07:28:16+00:00

I want these XML values read from the web service to a TextBlock ,

  • 0

I want these XML values read from the web service to a TextBlock, but this code causes a NullReferenceException. I’m sure from that the web service is not null. How can I solve this problem???

The line that causes the exception is commented and is:

// NOTE: NullReferenceException happens here
penalty = resultElements.Element("penalty").Value;

Code

namespace PhoneApp4
{
    public partial class pun : PhoneApplicationPage
    {
        WebClient pu;

        public pun()
        {
            InitializeComponent();
            pu = new WebClient();

            string pp ="http://82.212.89.6:888/mob/resources/punishments/studentPunishments/427400078/2";
            pu.DownloadStringAsync(new Uri(pp));

            pu.DownloadStringCompleted += new DownloadStringCompletedEventHandler(pun_DownloadStringCompleted);
            pu.DownloadProgressChanged += new DownloadProgressChangedEventHandler(pun_DownloadProgressChanged);
        }

        void pun_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            if (e.UserState as string == "mobiforge")
            {
                textBlock1.Text = e.BytesReceived.ToString() + " bytes received.";
            }
        }

        void pun_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error == null && !e.Cancelled)
            {
                XElement resultElements = XElement.Parse(e.Result);

                // NOTE: NullReferenceException happens here
                penalty = resultElements.Element("penalty").Value;
                semester = resultElements.Element("semester").Value;

                pun1.Text = penalty;
                ps1.Text = semester;
           }

        }
        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            MainPage tt = e.Content as MainPage;
            if (tt != null)
            {
                textBlock1.Text = tt.txtb1.Text;
            }
        }

        public string penalty { get; set; }
        public string semester { get; set; }
    }
}
  • 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-01T07:28:18+00:00Added an answer on June 1, 2026 at 7:28 am

    It works for me

    penalty = resultElements.Element("studentPunishmentsTable").Element("penalty").Value;
    semester = resultElements.Element("studentPunishmentsTable").Element("semester").Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my web.xml i want to read the welcome file from property file something
I want to parse xml files that have elements like these: <element>&amp</element> <element>&amp;</element> But
I want to extract all the properties from my pom.xml into a properties-file. These
This loads a set of values from an XML file and places them into
I am using Eclipse. I want to read number of XML files from a
I want to read the following XML file received from my e-commerce site and
I am writing a simple XML web service and want to return raw XML.
IS there any way that I can read config values in web.config with javascript
I want to save some values before i closed the app. But i don't
I'm writing out some xml from C# using the .net framework's XmlTextWriter. This works

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.